; LLVM IR from mitdbg/deneva :: system/txn.ll (ZN11Transaction15release_insertsEm)

; 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.RowPool = type { ptr, ptr }
%class.Transaction = type <{ %class.Array, i64, i64, i64, i64, i64, i32, [4 x i8], %class.Array.0, i64, i64, i32, [4 x i8] }>
%class.Array = type { ptr, i64, i64 }
%class.Array.0 = type { ptr, i64, i64 }
%class.row_t = type { ptr, ptr, i32, ptr, i64, i64, i8, i64 }

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

; 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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11Transaction15release_insertsEm(ptr noundef nonnull align 8 dereferenceable(116) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %24, %2
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = getelementptr inbounds %class.Transaction, ptr %7, i32 0, i32 8
  %11 = call noundef i64 @_ZN5ArrayIP5row_tE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10)
  %12 = icmp ult i64 %9, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %27

14:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = getelementptr inbounds %class.Transaction, ptr %7, i32 0, i32 8
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = call noundef ptr @_ZN5ArrayIP5row_tEixEm(ptr noundef nonnull align 8 dereferenceable(24) %15, i64 noundef %16)
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.row_t, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  call void @_ZN9mem_alloc4freeEPvm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, ptr noundef %20, i64 noundef 0)
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN5row_t8free_rowEv(ptr noundef nonnull align 8 dereferenceable(64) %21)
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN7RowPool3putEmP5row_t(ptr noundef nonnull align 8 dereferenceable(16) @row_pool, i64 noundef %22, ptr noundef %23)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %24

24:                                               ; preds = %14
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = add i64 %25, 1
  store i64 %26, ptr %5, align 8, !tbaa !9
  br label %8, !llvm.loop !15

27:                                               ; preds = %13
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN5ArrayIP5row_tE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5ArrayIP5row_tEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

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

declare void @_ZN5row_t8free_rowEv(ptr noundef nonnull align 8 dereferenceable(64)) #3

declare void @_ZN7RowPool3putEmP5row_t(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nounwind 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 = { "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 = { 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 0}
!12 = !{!"_ZTS5row_t", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !14, i64 48, !10, i64 56}
!13 = !{!"int", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 }
%class.RowPool = type { ptr, ptr }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11Transaction15release_insertsEm(ptr noundef nonnull align 8 dereferenceable(116) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 72
  %4 = tail call noundef i64 @_ZN5ArrayIP5row_tE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

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

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.07 = phi i64 [ %7, %.lr.ph ], [ 0, %2 ]
  %5 = tail call noundef ptr @_ZN5ArrayIP5row_tEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %.07)
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  tail call void @_ZN9mem_alloc4freeEPvm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, ptr noundef %6, i64 noundef 0)
  tail call void @_ZN5row_t8free_rowEv(ptr noundef nonnull align 8 dereferenceable(64) %5)
  tail call void @_ZN7RowPool3putEmP5row_t(ptr noundef nonnull align 8 dereferenceable(16) @row_pool, i64 noundef %1, ptr noundef nonnull %5)
  %7 = add nuw i64 %.07, 1
  %8 = tail call noundef i64 @_ZN5ArrayIP5row_tE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %9 = icmp ult i64 %7, %8
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN5ArrayIP5row_tE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5ArrayIP5row_tEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

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

declare void @_ZN5row_t8free_rowEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #2

declare void @_ZN7RowPool3putEmP5row_t(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, ptr noundef) local_unnamed_addr #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 = { mustprogress nounwind 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 = { "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, !7, i64 0}
!6 = !{!"_ZTS5row_t", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !11, i64 40, !12, i64 48, !11, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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