; LLVM IR from mitdbg/deneva :: system/pool.ll (ZN7QryPool4initEP8Workloadm)

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

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

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

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

declare i32 @__gxx_personality_v0(...)

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7QryPool4initEP8Workloadm(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, i64 noundef %2) #5 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %class.QryPool, ptr %14, i32 0, i32 1
  store ptr %15, ptr %16, align 8, !tbaa !11
  %17 = load i32, ptr @g_total_thread_cnt, align 4, !tbaa !13
  %18 = zext i32 %17 to i64
  %19 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %18, i64 8)
  %20 = extractvalue { i64, i1 } %19, 1
  %21 = extractvalue { i64, i1 } %19, 0
  %22 = select i1 %20, i64 -1, i64 %21
  %23 = call noalias noundef nonnull ptr @_Znam(i64 noundef %22) #6
  %24 = getelementptr inbounds %class.QryPool, ptr %14, i32 0, i32 0
  store ptr %23, ptr %24, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %67, %3
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = load i32, ptr @g_total_thread_cnt, align 4, !tbaa !13
  %28 = zext i32 %27 to i64
  %29 = icmp ult i64 %26, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  br label %71

31:                                               ; preds = %25
  %32 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 136) #6
  %33 = load i64, ptr %6, align 8, !tbaa !9
  invoke void @_ZN5boost8lockfree5queueIP9BaseQueryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %32, i64 noundef %33)
          to label %34 unwind label %44

34:                                               ; preds = %31
  %35 = getelementptr inbounds %class.QryPool, ptr %14, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds ptr, ptr %36, i64 %37
  store ptr %32, ptr %38, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %59, %34
  %40 = load i64, ptr %12, align 8, !tbaa !9
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = icmp ult i64 %40, %41
  br i1 %42, label %48, label %43

43:                                               ; preds = %39
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %66

44:                                               ; preds = %31
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %10, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, ptr %11, align 4
  call void @_ZdlPvm(ptr noundef %32, i64 noundef 136) #8
  br label %70

48:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %49 = call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef 136)
  store ptr %49, ptr %13, align 8, !tbaa !5
  %50 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 136) #6
  invoke void @_ZN9YCSBQueryC2Ev(ptr noundef nonnull align 8 dereferenceable(136) %50)
          to label %51 unwind label %62

51:                                               ; preds = %48
  store ptr %50, ptr %13, align 8, !tbaa !5
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  %54 = getelementptr inbounds ptr, ptr %53, i64 4
  %55 = load ptr, ptr %54, align 8
  call void %55(ptr noundef nonnull align 8 dereferenceable(136) %52)
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %56, ptr %7, align 8, !tbaa !5
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN7QryPool3putEmP9BaseQuery(ptr noundef nonnull align 8 dereferenceable(16) %14, i64 noundef %57, ptr noundef %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  br label %59

59:                                               ; preds = %51
  %60 = load i64, ptr %12, align 8, !tbaa !9
  %61 = add i64 %60, 1
  store i64 %61, ptr %12, align 8, !tbaa !9
  br label %39, !llvm.loop !18

62:                                               ; preds = %48
  %63 = landingpad { ptr, i32 }
          cleanup
  %64 = extractvalue { ptr, i32 } %63, 0
  store ptr %64, ptr %10, align 8
  %65 = extractvalue { ptr, i32 } %63, 1
  store i32 %65, ptr %11, align 4
  call void @_ZdlPvm(ptr noundef %50, i64 noundef 136) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %70

66:                                               ; preds = %43
  br label %67

67:                                               ; preds = %66
  %68 = load i64, ptr %8, align 8, !tbaa !9
  %69 = add i64 %68, 1
  store i64 %69, ptr %8, align 8, !tbaa !9
  br label %25, !llvm.loop !20

70:                                               ; preds = %62, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  br label %72

71:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  ret void

72:                                               ; preds = %70
  %73 = load ptr, ptr %10, align 8
  %74 = load i32, ptr %11, align 4
  %75 = insertvalue { ptr, i32 } poison, ptr %73, 0
  %76 = insertvalue { ptr, i32 } %75, i32 %74, 1
  resume { ptr, i32 } %76
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost8lockfree5queueIP9BaseQueryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136), i64 noundef) unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9YCSBQueryC2Ev(ptr noundef nonnull align 8 dereferenceable(136)) unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7QryPool3putEmP9BaseQuery(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, ptr noundef) #5 align 2

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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 #6 = { builtin allocsize(0) }
attributes #7 = { nounwind }
attributes #8 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS7QryPool", !6, i64 0, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !6, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

@g_total_thread_cnt = external local_unnamed_addr global i32, align 4
@mem_allocator = external global %class.mem_alloc, align 1

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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, 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 uwtable
define dso_local void @_ZN7QryPool4initEP8Workloadm(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load i32, ptr @g_total_thread_cnt, align 4, !tbaa !10
  %6 = zext i32 %5 to i64
  %7 = shl nuw nsw i64 %6, 3
  %8 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %7) #4
  store ptr %8, ptr %0, align 8, !tbaa !12
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %3
  %.not30 = icmp eq i64 %2, 0
  br i1 %.not30, label %.lr.ph23.split, label %.lr.ph23.split.us

.lr.ph23.split.us:                                ; preds = %.lr.ph23, %._crit_edge.us
  %.01621.us = phi i64 [ %20, %._crit_edge.us ], [ 0, %.lr.ph23 ]
  %9 = tail call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #4
  invoke void @_ZN5boost8lockfree5queueIP9BaseQueryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %9, i64 noundef %2)
          to label %.lr.ph.us unwind label %.split.us

.lr.ph.us:                                        ; preds = %.lr.ph23.split.us
  %10 = load ptr, ptr %0, align 8, !tbaa !12
  %11 = getelementptr inbounds ptr, ptr %10, i64 %.01621.us
  store ptr %9, ptr %11, align 8, !tbaa !13
  br label %12

12:                                               ; preds = %.lr.ph.us, %15
  %.020.us = phi i64 [ 0, %.lr.ph.us ], [ %19, %15 ]
  %13 = tail call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef 136)
  %14 = tail call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #4
  invoke void @_ZN9YCSBQueryC2Ev(ptr noundef nonnull align 8 dereferenceable(136) %14)
          to label %15 unwind label %.split27.us

15:                                               ; preds = %12
  %16 = load ptr, ptr %14, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %16, i64 32
  %18 = load ptr, ptr %17, align 8
  tail call void %18(ptr noundef nonnull align 8 dereferenceable(136) %14)
  tail call void @_ZN7QryPool3putEmP9BaseQuery(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %.01621.us, ptr noundef nonnull %14)
  %19 = add nuw i64 %.020.us, 1
  %exitcond.not = icmp eq i64 %19, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %12, !llvm.loop !16

._crit_edge.us:                                   ; preds = %15
  %20 = add nuw nsw i64 %.01621.us, 1
  %21 = load i32, ptr @g_total_thread_cnt, align 4, !tbaa !10
  %22 = zext i32 %21 to i64
  %23 = icmp ult i64 %20, %22
  br i1 %23, label %.lr.ph23.split.us, label %._crit_edge24, !llvm.loop !18

.split.us:                                        ; preds = %.lr.ph23.split.us
  %24 = landingpad { ptr, i32 }
          cleanup
  br label %35

.split27.us:                                      ; preds = %12
  %25 = landingpad { ptr, i32 }
          cleanup
  br label %35

._crit_edge24:                                    ; preds = %._crit_edge.us, %27, %3
  ret void

.lr.ph23.split:                                   ; preds = %.lr.ph23, %27
  %.01621 = phi i64 [ %30, %27 ], [ 0, %.lr.ph23 ]
  %26 = tail call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #4
  invoke void @_ZN5boost8lockfree5queueIP9BaseQueryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %26, i64 noundef 0)
          to label %27 unwind label %.split

27:                                               ; preds = %.lr.ph23.split
  %28 = load ptr, ptr %0, align 8, !tbaa !12
  %29 = getelementptr inbounds ptr, ptr %28, i64 %.01621
  store ptr %26, ptr %29, align 8, !tbaa !13
  %30 = add nuw nsw i64 %.01621, 1
  %31 = load i32, ptr @g_total_thread_cnt, align 4, !tbaa !10
  %32 = zext i32 %31 to i64
  %33 = icmp ult i64 %30, %32
  br i1 %33, label %.lr.ph23.split, label %._crit_edge24, !llvm.loop !18

.split:                                           ; preds = %.lr.ph23.split
  %34 = landingpad { ptr, i32 }
          cleanup
  br label %35

35:                                               ; preds = %.split, %.split.us, %.split27.us
  %.lcssa40.sink = phi ptr [ %14, %.split27.us ], [ %26, %.split ], [ %9, %.split.us ]
  %.pn = phi { ptr, i32 } [ %25, %.split27.us ], [ %34, %.split ], [ %24, %.split.us ]
  tail call void @_ZdlPvm(ptr noundef nonnull %.lcssa40.sink, i64 noundef 136) #5
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost8lockfree5queueIP9BaseQueryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136), i64 noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9YCSBQueryC2Ev(ptr noundef nonnull align 8 dereferenceable(136)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7QryPool3putEmP9BaseQuery(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, ptr noundef) local_unnamed_addr #3 align 2

attributes #0 = { 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 #1 = { 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 #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 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 = { builtin allocsize(0) }
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, !7, i64 8}
!6 = !{!"_ZTS7QryPool", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !9, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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