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

; 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 }
%struct.msg_entry = type { ptr, i64, i64 }
%class.MsgPool = type { ptr, ptr }

@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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7MsgPool3putEP9msg_entry(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.msg_entry, ptr %7, i32 0, i32 0
  store ptr null, ptr %8, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.msg_entry, ptr %9, i32 0, i32 1
  store i64 -1, ptr %10, align 8, !tbaa !12
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.msg_entry, ptr %11, i32 0, i32 2
  store i64 -1, ptr %12, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %13

13:                                               ; preds = %23, %2
  %14 = getelementptr inbounds %class.MsgPool, ptr %6, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %15, ptr noundef nonnull align 8 dereferenceable(8) %4)
  br i1 %16, label %21, label %17

17:                                               ; preds = %13
  %18 = load i32, ptr %5, align 4, !tbaa !14
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %5, align 4, !tbaa !14
  %20 = icmp slt i32 %18, 10
  br label %21

21:                                               ; preds = %17, %13
  %22 = phi i1 [ false, %13 ], [ %20, %17 ]
  br i1 %22, label %23, label %24

23:                                               ; preds = %21
  br label %13, !llvm.loop !18

24:                                               ; preds = %21
  %25 = load i32, ptr %5, align 4, !tbaa !14
  %26 = icmp sge i32 %25, 10
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN9mem_alloc4freeEPvm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, ptr noundef %28, i64 noundef 24)
  br label %29

29:                                               ; preds = %27, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136), ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 0}
!10 = !{!"_ZTS9msg_entry", !6, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTS7MsgPool", !6, i64 0, !6, i64 8}
!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 }

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7MsgPool3putEP9msg_entry(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %1, align 8, !tbaa !9
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, i8 -1, i64 16, i1 false)
  %5 = load ptr, ptr %0, align 8, !tbaa !12
  %6 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %5, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %6, label %.critedge.thread, label %7

7:                                                ; preds = %2
  %8 = load ptr, ptr %0, align 8, !tbaa !12
  %9 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %8, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %9, label %.critedge.thread, label %10

10:                                               ; preds = %7
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %12 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %11, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %12, label %.critedge.thread, label %13

13:                                               ; preds = %10
  %14 = load ptr, ptr %0, align 8, !tbaa !12
  %15 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %14, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %15, label %.critedge.thread, label %16

16:                                               ; preds = %13
  %17 = load ptr, ptr %0, align 8, !tbaa !12
  %18 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %17, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %18, label %.critedge.thread, label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr %0, align 8, !tbaa !12
  %21 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %20, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %21, label %.critedge.thread, label %22

22:                                               ; preds = %19
  %23 = load ptr, ptr %0, align 8, !tbaa !12
  %24 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %23, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %24, label %.critedge.thread, label %25

25:                                               ; preds = %22
  %26 = load ptr, ptr %0, align 8, !tbaa !12
  %27 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %26, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %27, label %.critedge.thread, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr %0, align 8, !tbaa !12
  %30 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %29, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %30, label %.critedge.thread, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr %0, align 8, !tbaa !12
  %33 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %32, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br i1 %33, label %.critedge.thread, label %.critedge

.critedge:                                        ; preds = %31
  %34 = load ptr, ptr %0, align 8, !tbaa !12
  %35 = call noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136) %34, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN9mem_alloc4freeEPvm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, ptr noundef %36, i64 noundef 24)
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %31, %28, %25, %22, %19, %16, %13, %10, %7, %2, %.critedge
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN5boost8lockfree5queueIP9msg_entryJEE4pushERKS3_(ptr noundef nonnull align 8 dereferenceable(136), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 0}
!10 = !{!"_ZTS9msg_entry", !6, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTS7MsgPool", !6, i64 0, !6, i64 8}


; Effective O3 passes: ADCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass