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

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

@g_total_thread_cnt = external global i32, align 4

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

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

29:                                               ; preds = %24
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %70

30:                                               ; preds = %24
  %31 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 136) #5
  %32 = load i64, ptr %6, align 8, !tbaa !9
  invoke void @_ZN5boost8lockfree5queueIP10TxnManagerJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %31, i64 noundef %32)
          to label %33 unwind label %43

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

38:                                               ; preds = %63, %33
  %39 = load i64, ptr %12, align 8, !tbaa !9
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %47, label %42

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

43:                                               ; preds = %30
  %44 = landingpad { ptr, i32 }
          cleanup
  %45 = extractvalue { ptr, i32 } %44, 0
  store ptr %45, ptr %10, align 8
  %46 = extractvalue { ptr, i32 } %44, 1
  store i32 %46, ptr %11, align 4
  call void @_ZdlPvm(ptr noundef %31, i64 noundef 136) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  br label %71

47:                                               ; preds = %38
  %48 = getelementptr inbounds %class.TxnManPool, ptr %13, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  %50 = load ptr, ptr %49, align 8, !tbaa !16
  %51 = getelementptr inbounds ptr, ptr %50, i64 3
  %52 = load ptr, ptr %51, align 8
  %53 = call noundef i32 %52(ptr noundef nonnull align 8 dereferenceable(120) %49, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load i64, ptr %8, align 8, !tbaa !9
  %56 = getelementptr inbounds %class.TxnManPool, ptr %13, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = load ptr, ptr %54, align 8, !tbaa !16
  %59 = getelementptr inbounds ptr, ptr %58, i64 2
  %60 = load ptr, ptr %59, align 8
  call void %60(ptr noundef nonnull align 8 dereferenceable(544) %54, i64 noundef %55, ptr noundef %57)
  %61 = load i64, ptr %8, align 8, !tbaa !9
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN10TxnManPool3putEmP10TxnManager(ptr noundef nonnull align 8 dereferenceable(16) %13, i64 noundef %61, ptr noundef %62)
  br label %63

63:                                               ; preds = %47
  %64 = load i64, ptr %12, align 8, !tbaa !9
  %65 = add i64 %64, 1
  store i64 %65, ptr %12, align 8, !tbaa !9
  br label %38, !llvm.loop !18

66:                                               ; preds = %42
  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 %24, !llvm.loop !20

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

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

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

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

declare i32 @__gxx_personality_v0(...)

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

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

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { nounwind }
attributes #7 = { 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 = !{!"_ZTS10TxnManPool", !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"

@g_total_thread_cnt = external local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10TxnManPool4initEP8Workloadm(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load i32, ptr @g_total_thread_cnt, align 4, !tbaa !10
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 3
  %9 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %8) #4
  store ptr %9, ptr %0, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %._crit_edge17, label %.lr.ph16

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

.lr.ph16.split.us:                                ; preds = %.lr.ph16, %._crit_edge.us
  %.01214.us = phi i64 [ %26, %._crit_edge.us ], [ 0, %.lr.ph16 ]
  %10 = call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #4
  invoke void @_ZN5boost8lockfree5queueIP10TxnManagerJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %10, i64 noundef %2)
          to label %.lr.ph.us unwind label %.split.us

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

13:                                               ; preds = %.lr.ph.us, %13
  %.013.us = phi i64 [ 0, %.lr.ph.us ], [ %25, %13 ]
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %15, i64 24
  %17 = load ptr, ptr %16, align 8
  %18 = call noundef i32 %17(ptr noundef nonnull align 8 dereferenceable(120) %14, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %19 = load ptr, ptr %4, align 8, !tbaa !13
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %19, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %23 = load ptr, ptr %22, align 8
  call void %23(ptr noundef nonnull align 8 dereferenceable(544) %19, i64 noundef %.01214.us, ptr noundef %20)
  %24 = load ptr, ptr %4, align 8, !tbaa !13
  call void @_ZN10TxnManPool3putEmP10TxnManager(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %.01214.us, ptr noundef %24)
  %25 = add nuw i64 %.013.us, 1
  %exitcond.not = icmp eq i64 %25, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %13, !llvm.loop !16

._crit_edge.us:                                   ; preds = %13
  %26 = add nuw nsw i64 %.01214.us, 1
  %27 = load i32, ptr @g_total_thread_cnt, align 4, !tbaa !10
  %28 = zext i32 %27 to i64
  %29 = icmp ult i64 %26, %28
  br i1 %29, label %.lr.ph16.split.us, label %._crit_edge17, !llvm.loop !18

.split.us:                                        ; preds = %.lr.ph16.split.us
  %30 = landingpad { ptr, i32 }
          cleanup
  br label %40

._crit_edge17:                                    ; preds = %._crit_edge.us, %32, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret void

.lr.ph16.split:                                   ; preds = %.lr.ph16, %32
  %.01214 = phi i64 [ %35, %32 ], [ 0, %.lr.ph16 ]
  %31 = tail call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #4
  invoke void @_ZN5boost8lockfree5queueIP10TxnManagerJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %31, i64 noundef 0)
          to label %32 unwind label %.split

32:                                               ; preds = %.lr.ph16.split
  %33 = load ptr, ptr %0, align 8, !tbaa !12
  %34 = getelementptr inbounds ptr, ptr %33, i64 %.01214
  store ptr %31, ptr %34, align 8, !tbaa !13
  %35 = add nuw nsw i64 %.01214, 1
  %36 = load i32, ptr @g_total_thread_cnt, align 4, !tbaa !10
  %37 = zext i32 %36 to i64
  %38 = icmp ult i64 %35, %37
  br i1 %38, label %.lr.ph16.split, label %._crit_edge17, !llvm.loop !18

.split:                                           ; preds = %.lr.ph16.split
  %39 = landingpad { ptr, i32 }
          cleanup
  br label %40

40:                                               ; preds = %.split.us, %.split
  %.us-phi = phi ptr [ %31, %.split ], [ %10, %.split.us ]
  %.us-phi18 = phi { ptr, i32 } [ %39, %.split ], [ %30, %.split.us ]
  call void @_ZdlPvm(ptr noundef nonnull %.us-phi, i64 noundef 136) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  resume { ptr, i32 } %.us-phi18
}

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

; Function Attrs: mustprogress 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) local_unnamed_addr #1

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

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress 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 = { builtin allocsize(0) }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!"_ZTS10TxnManPool", !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