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

; 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.MessageQueue = type { ptr, %"class.std::vector", ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<msg_entry *, std::allocator<msg_entry *>>::_Vector_impl" }
%"struct.std::_Vector_base<msg_entry *, std::allocator<msg_entry *>>::_Vector_impl" = type { %"struct.std::_Vector_base<msg_entry *, std::allocator<msg_entry *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<msg_entry *, std::allocator<msg_entry *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.TxnManager = type { ptr, ptr, ptr, i8, ptr, i32, i8, i32, i32, i8, i64, i64, i64, i64, ptr, ptr, ptr, i64, i8, i8, ptr, ptr, i64, i64, i64, %class.TxnStats, i32, i32, i32, i8, i32, %class.Array.0, i32, ptr, ptr, i32, %union.sem_t }
%class.TxnStats = type { i64, i64, i64, i64, i64, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, i64, i64, double, double, double, double, double, double, double, double }
%class.Array.0 = type { ptr, i64, i64 }
%union.sem_t = type { i64, [24 x i8] }
%class.BaseQuery = type { ptr, i64, %class.Array.1, %class.Array.1, %class.Array.1, %class.Array.1 }
%class.Array.1 = type { ptr, i64, i64 }

@g_node_cnt = external global i32, align 4
@g_node_id = external global i32, align 4
@msg_queue = external global %class.MessageQueue, 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
declare dso_local noundef i64 @_ZN10TxnManager10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(544)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10TxnManager21send_prepare_messagesEv(ptr noundef nonnull align 8 dereferenceable(544) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %class.TxnManager, ptr %4, i32 0, i32 21
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds %class.BaseQuery, ptr %6, i32 0, i32 3
  %8 = call noundef i64 @_ZN5ArrayImE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %9 = sub i64 %8, 1
  %10 = trunc i64 %9 to i32
  %11 = getelementptr inbounds %class.TxnManager, ptr %4, i32 0, i32 32
  store i32 %10, ptr %11, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !20
  br label %12

12:                                               ; preds = %44, %1
  %13 = load i64, ptr %3, align 8, !tbaa !20
  %14 = getelementptr inbounds %class.TxnManager, ptr %4, i32 0, i32 21
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %class.BaseQuery, ptr %15, i32 0, i32 3
  %17 = call noundef i64 @_ZN5ArrayImE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %16)
  %18 = icmp ult i64 %13, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %47

20:                                               ; preds = %12
  %21 = getelementptr inbounds %class.TxnManager, ptr %4, i32 0, i32 21
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %class.BaseQuery, ptr %22, i32 0, i32 3
  %24 = load i64, ptr %3, align 8, !tbaa !20
  %25 = call noundef i64 @_ZN5ArrayImEixEm(ptr noundef nonnull align 8 dereferenceable(24) %23, i64 noundef %24)
  %26 = load i32, ptr @g_node_cnt, align 4, !tbaa !21
  %27 = zext i32 %26 to i64
  %28 = urem i64 %25, %27
  %29 = load i32, ptr @g_node_id, align 4, !tbaa !21
  %30 = zext i32 %29 to i64
  %31 = icmp eq i64 %28, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %20
  br label %44

33:                                               ; preds = %20
  %34 = call noundef i64 @_ZN10TxnManager10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(544) %4)
  %35 = call noundef ptr @_ZN7Message14create_messageEP10TxnManager10RemReqType(ptr noundef %4, i32 noundef 16)
  %36 = getelementptr inbounds %class.TxnManager, ptr %4, i32 0, i32 21
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds %class.BaseQuery, ptr %37, i32 0, i32 3
  %39 = load i64, ptr %3, align 8, !tbaa !20
  %40 = call noundef i64 @_ZN5ArrayImEixEm(ptr noundef nonnull align 8 dereferenceable(24) %38, i64 noundef %39)
  %41 = load i32, ptr @g_node_cnt, align 4, !tbaa !21
  %42 = zext i32 %41 to i64
  %43 = urem i64 %40, %42
  call void @_ZN12MessageQueue7enqueueEmP7Messagem(ptr noundef nonnull align 8 dereferenceable(40) @msg_queue, i64 noundef %34, ptr noundef %35, i64 noundef %43)
  br label %44

44:                                               ; preds = %33, %32
  %45 = load i64, ptr %3, align 8, !tbaa !20
  %46 = add i64 %45, 1
  store i64 %46, ptr %3, align 8, !tbaa !20
  br label %12, !llvm.loop !22

47:                                               ; preds = %19
  ret void
}

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

declare void @_ZN12MessageQueue7enqueueEmP7Messagem(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, ptr noundef, i64 noundef) #3

declare noundef ptr @_ZN7Message14create_messageEP10TxnManager10RemReqType(ptr noundef, i32 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, !6, i64 144}
!10 = !{!"_ZTS10TxnManager", !6, i64 8, !6, i64 16, !11, i64 24, !6, i64 32, !12, i64 40, !11, i64 44, !12, i64 48, !12, i64 52, !11, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !13, i64 120, !11, i64 128, !11, i64 129, !6, i64 136, !6, i64 144, !13, i64 152, !13, i64 160, !13, i64 168, !14, i64 176, !12, i64 432, !12, i64 436, !12, i64 440, !11, i64 444, !16, i64 448, !17, i64 456, !12, i64 480, !6, i64 488, !6, i64 496, !18, i64 504, !7, i64 512}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTS8TxnStats", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !15, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !15, i64 72, !15, i64 80, !15, i64 88, !15, i64 96, !15, i64 104, !15, i64 112, !15, i64 120, !15, i64 128, !15, i64 136, !15, i64 144, !15, i64 152, !15, i64 160, !15, i64 168, !13, i64 176, !13, i64 184, !15, i64 192, !15, i64 200, !15, i64 208, !15, i64 216, !15, i64 224, !15, i64 232, !15, i64 240, !15, i64 248}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_ZTS12CALVIN_PHASE", !7, i64 0}
!17 = !{!"_ZTS5ArrayIP5row_tE", !6, i64 0, !13, i64 8, !13, i64 16}
!18 = !{!"_ZTS8access_t", !7, i64 0}
!19 = !{!10, !12, i64 480}
!20 = !{!13, !13, i64 0}
!21 = !{!12, !12, i64 0}
!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.MessageQueue = type { ptr, %"class.std::vector", ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<msg_entry *, std::allocator<msg_entry *>>::_Vector_impl" }
%"struct.std::_Vector_base<msg_entry *, std::allocator<msg_entry *>>::_Vector_impl" = type { %"struct.std::_Vector_base<msg_entry *, std::allocator<msg_entry *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<msg_entry *, std::allocator<msg_entry *>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@g_node_cnt = external local_unnamed_addr global i32, align 4
@g_node_id = external local_unnamed_addr global i32, align 4
@msg_queue = external global %class.MessageQueue, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN10TxnManager10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(544)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10TxnManager21send_prepare_messagesEv(ptr noundef nonnull align 8 dereferenceable(544) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 144
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 40
  %5 = tail call noundef i64 @_ZN5ArrayImE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  %6 = trunc i64 %5 to i32
  %7 = add i32 %6, -1
  %8 = getelementptr inbounds i8, ptr %0, i64 480
  store i32 %7, ptr %8, align 8, !tbaa !18
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 40
  %11 = tail call noundef i64 @_ZN5ArrayImE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10)
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %30, %1
  ret void

.lr.ph:                                           ; preds = %1, %30
  %.04 = phi i64 [ %31, %30 ], [ 0, %1 ]
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 40
  %14 = tail call noundef i64 @_ZN5ArrayImEixEm(ptr noundef nonnull align 8 dereferenceable(24) %13, i64 noundef %.04)
  %15 = load i32, ptr @g_node_cnt, align 4, !tbaa !19
  %16 = zext i32 %15 to i64
  %17 = urem i64 %14, %16
  %18 = load i32, ptr @g_node_id, align 4, !tbaa !19
  %19 = zext i32 %18 to i64
  %20 = icmp eq i64 %17, %19
  br i1 %20, label %30, label %21

21:                                               ; preds = %.lr.ph
  %22 = tail call noundef i64 @_ZN10TxnManager10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(544) %0)
  %23 = tail call noundef ptr @_ZN7Message14create_messageEP10TxnManager10RemReqType(ptr noundef nonnull %0, i32 noundef 16)
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 40
  %26 = tail call noundef i64 @_ZN5ArrayImEixEm(ptr noundef nonnull align 8 dereferenceable(24) %25, i64 noundef %.04)
  %27 = load i32, ptr @g_node_cnt, align 4, !tbaa !19
  %28 = zext i32 %27 to i64
  %29 = urem i64 %26, %28
  tail call void @_ZN12MessageQueue7enqueueEmP7Messagem(ptr noundef nonnull align 8 dereferenceable(40) @msg_queue, i64 noundef %22, ptr noundef %23, i64 noundef %29)
  br label %30

30:                                               ; preds = %.lr.ph, %21
  %31 = add nuw i64 %.04, 1
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 40
  %34 = tail call noundef i64 @_ZN5ArrayImE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %33)
  %35 = icmp ult i64 %31, %34
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !20
}

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

declare void @_ZN12MessageQueue7enqueueEmP7Messagem(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare noundef ptr @_ZN7Message14create_messageEP10TxnManager10RemReqType(ptr noundef, i32 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 144}
!6 = !{!"_ZTS10TxnManager", !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !11, i64 40, !10, i64 44, !11, i64 48, !11, i64 52, !10, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !12, i64 120, !10, i64 128, !10, i64 129, !7, i64 136, !7, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !13, i64 176, !11, i64 432, !11, i64 436, !11, i64 440, !10, i64 444, !15, i64 448, !16, i64 456, !11, i64 480, !7, i64 488, !7, i64 496, !17, i64 504, !8, i64 512}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"_ZTS8TxnStats", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !14, i64 128, !14, i64 136, !14, i64 144, !14, i64 152, !14, i64 160, !14, i64 168, !12, i64 176, !12, i64 184, !14, i64 192, !14, i64 200, !14, i64 208, !14, i64 216, !14, i64 224, !14, i64 232, !14, i64 240, !14, i64 248}
!14 = !{!"double", !8, i64 0}
!15 = !{!"_ZTS12CALVIN_PHASE", !8, i64 0}
!16 = !{!"_ZTS5ArrayIP5row_tE", !7, i64 0, !12, i64 8, !12, i64 16}
!17 = !{!"_ZTS8access_t", !8, i64 0}
!18 = !{!6, !11, i64 480}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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