; LLVM IR from mitdbg/deneva :: system/work_queue.ll (ZN10QWorkQueue4initEv)

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

@g_node_cnt = external global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10QWorkQueue4initEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = getelementptr inbounds %class.QWorkQueue, ptr %6, i32 0, i32 5
  store ptr null, ptr %7, align 8, !tbaa !9
  %8 = getelementptr inbounds %class.QWorkQueue, ptr %6, i32 0, i32 4
  store i64 0, ptr %8, align 8, !tbaa !12
  %9 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 136) #5
  invoke void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %9, i64 noundef 0)
          to label %10 unwind label %32

10:                                               ; preds = %1
  %11 = getelementptr inbounds %class.QWorkQueue, ptr %6, i32 0, i32 2
  store ptr %9, ptr %11, align 8, !tbaa !13
  %12 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 136) #5
  invoke void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %12, i64 noundef 0)
          to label %13 unwind label %36

13:                                               ; preds = %10
  %14 = getelementptr inbounds %class.QWorkQueue, ptr %6, i32 0, i32 0
  store ptr %12, ptr %14, align 8, !tbaa !14
  %15 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 136) #5
  invoke void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %15, i64 noundef 0)
          to label %16 unwind label %40

16:                                               ; preds = %13
  %17 = getelementptr inbounds %class.QWorkQueue, ptr %6, i32 0, i32 1
  store ptr %15, ptr %17, align 8, !tbaa !15
  %18 = load i32, ptr @g_node_cnt, align 4, !tbaa !16
  %19 = zext i32 %18 to i64
  %20 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %19, i64 8)
  %21 = extractvalue { i64, i1 } %20, 1
  %22 = extractvalue { i64, i1 } %20, 0
  %23 = select i1 %21, i64 -1, i64 %22
  %24 = call noalias noundef nonnull ptr @_Znam(i64 noundef %23) #5
  %25 = getelementptr inbounds %class.QWorkQueue, ptr %6, i32 0, i32 3
  store ptr %24, ptr %25, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  store i64 0, ptr %5, align 8, !tbaa !19
  br label %26

26:                                               ; preds = %51, %16
  %27 = load i64, ptr %5, align 8, !tbaa !19
  %28 = load i32, ptr @g_node_cnt, align 4, !tbaa !16
  %29 = zext i32 %28 to i64
  %30 = icmp ult i64 %27, %29
  br i1 %30, label %44, label %31

31:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %58

32:                                               ; preds = %1
  %33 = landingpad { ptr, i32 }
          cleanup
  %34 = extractvalue { ptr, i32 } %33, 0
  store ptr %34, ptr %3, align 8
  %35 = extractvalue { ptr, i32 } %33, 1
  store i32 %35, ptr %4, align 4
  call void @_ZdlPvm(ptr noundef %9, i64 noundef 136) #7
  br label %59

36:                                               ; preds = %10
  %37 = landingpad { ptr, i32 }
          cleanup
  %38 = extractvalue { ptr, i32 } %37, 0
  store ptr %38, ptr %3, align 8
  %39 = extractvalue { ptr, i32 } %37, 1
  store i32 %39, ptr %4, align 4
  call void @_ZdlPvm(ptr noundef %12, i64 noundef 136) #7
  br label %59

40:                                               ; preds = %13
  %41 = landingpad { ptr, i32 }
          cleanup
  %42 = extractvalue { ptr, i32 } %41, 0
  store ptr %42, ptr %3, align 8
  %43 = extractvalue { ptr, i32 } %41, 1
  store i32 %43, ptr %4, align 4
  call void @_ZdlPvm(ptr noundef %15, i64 noundef 136) #7
  br label %59

44:                                               ; preds = %26
  %45 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 136) #5
  invoke void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %45, i64 noundef 0)
          to label %46 unwind label %54

46:                                               ; preds = %44
  %47 = getelementptr inbounds %class.QWorkQueue, ptr %6, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !18
  %49 = load i64, ptr %5, align 8, !tbaa !19
  %50 = getelementptr inbounds ptr, ptr %48, i64 %49
  store ptr %45, ptr %50, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %46
  %52 = load i64, ptr %5, align 8, !tbaa !19
  %53 = add i64 %52, 1
  store i64 %53, ptr %5, align 8, !tbaa !19
  br label %26, !llvm.loop !20

54:                                               ; preds = %44
  %55 = landingpad { ptr, i32 }
          cleanup
  %56 = extractvalue { ptr, i32 } %55, 0
  store ptr %56, ptr %3, align 8
  %57 = extractvalue { ptr, i32 } %55, 1
  store i32 %57, ptr %4, align 4
  call void @_ZdlPvm(ptr noundef %45, i64 noundef 136) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %59

58:                                               ; preds = %31
  ret void

59:                                               ; preds = %54, %40, %36, %32
  %60 = load ptr, ptr %3, align 8
  %61 = load i32, ptr %4, align 4
  %62 = insertvalue { ptr, i32 } poison, ptr %60, 0
  %63 = insertvalue { ptr, i32 } %62, i32 %61, 1
  resume { ptr, i32 } %63
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(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) #2

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

; 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) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 40}
!10 = !{!"_ZTS10QWorkQueue", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !11, i64 48}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 32}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !6, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!10, !6, i64 24}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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"

@g_node_cnt = external local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10QWorkQueue4initEv(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  %3 = tail call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #4
  invoke void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %3, i64 noundef 0)
          to label %4 unwind label %16

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %3, ptr %5, align 8, !tbaa !5
  %6 = tail call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #4
  invoke void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %6, i64 noundef 0)
          to label %7 unwind label %18

7:                                                ; preds = %4
  store ptr %6, ptr %0, align 8, !tbaa !11
  %8 = tail call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #4
  invoke void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %8, i64 noundef 0)
          to label %9 unwind label %20

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %8, ptr %10, align 8, !tbaa !12
  %11 = load i32, ptr @g_node_cnt, align 4, !tbaa !13
  %12 = zext i32 %11 to i64
  %13 = shl nuw nsw i64 %12, 3
  %14 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %13) #4
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %14, ptr %15, align 8, !tbaa !15
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %23, %9
  ret void

16:                                               ; preds = %1
  %17 = landingpad { ptr, i32 }
          cleanup
  br label %32

18:                                               ; preds = %4
  %19 = landingpad { ptr, i32 }
          cleanup
  br label %32

20:                                               ; preds = %7
  %21 = landingpad { ptr, i32 }
          cleanup
  br label %32

.lr.ph:                                           ; preds = %9, %23
  %.08 = phi i64 [ %26, %23 ], [ 0, %9 ]
  %22 = tail call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #4
  invoke void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(ptr noundef nonnull align 8 dereferenceable(136) %22, i64 noundef 0)
          to label %23 unwind label %30

23:                                               ; preds = %.lr.ph
  %24 = load ptr, ptr %15, align 8, !tbaa !15
  %25 = getelementptr inbounds ptr, ptr %24, i64 %.08
  store ptr %22, ptr %25, align 8, !tbaa !16
  %26 = add nuw nsw i64 %.08, 1
  %27 = load i32, ptr @g_node_cnt, align 4, !tbaa !13
  %28 = zext i32 %27 to i64
  %29 = icmp ult i64 %26, %28
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !17

30:                                               ; preds = %.lr.ph
  %31 = landingpad { ptr, i32 }
          cleanup
  br label %32

32:                                               ; preds = %30, %20, %18, %16
  %.lcssa.sink = phi ptr [ %22, %30 ], [ %8, %20 ], [ %6, %18 ], [ %3, %16 ]
  %.pn = phi { ptr, i32 } [ %31, %30 ], [ %21, %20 ], [ %19, %18 ], [ %17, %16 ]
  tail call void @_ZdlPvm(ptr noundef nonnull %.lcssa.sink, i64 noundef 136) #5
  resume { ptr, i32 } %.pn
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost8lockfree5queueIP16work_queue_entryJEEC2Em(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 #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { 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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 16}
!6 = !{!"_ZTS10QWorkQueue", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !10, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!6, !7, i64 24}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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