; LLVM IR from mitdbg/deneva :: system/txn_table.ll (ZN8TxnTable4initEv)

; 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.TxnTable = type { i64, ptr }
%struct.pool_node = type { ptr, ptr, i8, i64, i64 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8TxnTable4initEv(ptr noundef nonnull align 8 dereferenceable(16) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = load i32, ptr @g_inflight_max, align 4, !tbaa !9
  %6 = add nsw i32 %5, 1
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 0
  store i64 %7, ptr %8, align 8, !tbaa !11
  %9 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 0
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = mul i64 8, %10
  %12 = call noundef ptr @_ZN9mem_alloc11align_allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef %11)
  %13 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 1
  store ptr %12, ptr %13, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %63, %1
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = icmp ult i64 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %66

21:                                               ; preds = %14
  %22 = call noundef ptr @_ZN9mem_alloc11align_allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef 40)
  %23 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds ptr, ptr %24, i64 %26
  store ptr %22, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %29, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.pool_node, ptr %33, i32 0, i32 0
  store ptr null, ptr %34, align 8, !tbaa !15
  %35 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds ptr, ptr %36, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.pool_node, ptr %40, i32 0, i32 1
  store ptr null, ptr %41, align 8, !tbaa !18
  %42 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %43, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.pool_node, ptr %47, i32 0, i32 3
  store i64 0, ptr %48, align 8, !tbaa !19
  %49 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.pool_node, ptr %54, i32 0, i32 2
  store volatile i8 0, ptr %55, align 8, !tbaa !20
  %56 = getelementptr inbounds %class.TxnTable, ptr %4, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = load i32, ptr %3, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds ptr, ptr %57, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.pool_node, ptr %61, i32 0, i32 4
  store i64 -1, ptr %62, align 8, !tbaa !21
  br label %63

63:                                               ; preds = %21
  %64 = load i32, ptr %3, align 4, !tbaa !9
  %65 = add i32 %64, 1
  store i32 %65, ptr %3, align 4, !tbaa !9
  br label %14, !llvm.loop !22

66:                                               ; preds = %20
  ret void
}

declare noundef ptr @_ZN9mem_alloc11align_allocEm(ptr noundef nonnull align 1 dereferenceable(1), 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: 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 = { "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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS8TxnTable", !13, i64 0, !6, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"_ZTS9pool_node", !6, i64 0, !6, i64 8, !17, i64 16, !13, i64 24, !13, i64 32}
!17 = !{!"bool", !7, i64 0}
!18 = !{!16, !6, i64 8}
!19 = !{!16, !13, i64 24}
!20 = !{!16, !17, i64 16}
!21 = !{!16, !13, i64 32}
!22 = distinct !{!22, !23}
!23 = !{!"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 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8TxnTable4initEv(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr @g_inflight_max, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  %4 = sext i32 %3 to i64
  store i64 %4, ptr %0, align 8, !tbaa !9
  %5 = shl nsw i64 %4, 3
  %6 = tail call noundef ptr @_ZN9mem_alloc11align_allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef %5)
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %6, ptr %7, align 8, !tbaa !13
  %8 = load i64, ptr %0, align 8, !tbaa !9
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %9 = phi i64 [ %23, %.lr.ph ], [ 0, %1 ]
  %.09 = phi i32 [ %22, %.lr.ph ], [ 0, %1 ]
  %10 = tail call noundef ptr @_ZN9mem_alloc11align_allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef 40)
  %11 = load ptr, ptr %7, align 8, !tbaa !13
  %12 = getelementptr inbounds ptr, ptr %11, i64 %9
  store ptr %10, ptr %12, align 8, !tbaa !14
  %13 = load ptr, ptr %7, align 8, !tbaa !13
  %14 = getelementptr inbounds ptr, ptr %13, i64 %9
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  store ptr null, ptr %15, align 8, !tbaa !15
  %16 = load ptr, ptr %14, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  store ptr null, ptr %17, align 8, !tbaa !18
  %18 = load ptr, ptr %14, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %18, i64 24
  store i64 0, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %18, i64 16
  store volatile i8 0, ptr %20, align 8, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %18, i64 32
  store i64 -1, ptr %21, align 8, !tbaa !21
  %22 = add i32 %.09, 1
  %23 = zext i32 %22 to i64
  %24 = load i64, ptr %0, align 8, !tbaa !9
  %25 = icmp ugt i64 %24, %23
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !22
}

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

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 = { "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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS8TxnTable", !11, i64 0, !12, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"_ZTS9pool_node", !12, i64 0, !12, i64 8, !17, i64 16, !11, i64 24, !11, i64 32}
!17 = !{!"bool", !7, i64 0}
!18 = !{!16, !12, i64 8}
!19 = !{!16, !11, i64 24}
!20 = !{!16, !17, i64 16}
!21 = !{!16, !11, i64 32}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass