; LLVM IR from mitdbg/deneva :: system/thread.ll (ZN6Thread27send_init_done_to_all_nodesEv)

; 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 }

@g_total_node_cnt = external global i32, align 4
@g_node_id = external global i32, align 4
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@msg_queue = external global %class.MessageQueue, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Thread27send_init_done_to_all_nodesEv(ptr noundef nonnull align 8 dereferenceable(64) %0) #0 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %5

5:                                                ; preds = %23, %1
  %6 = load i64, ptr %3, align 8, !tbaa !9
  %7 = load i32, ptr @g_total_node_cnt, align 4, !tbaa !11
  %8 = zext i32 %7 to i64
  %9 = icmp ult i64 %6, %8
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %5
  %12 = load i64, ptr %3, align 8, !tbaa !9
  %13 = load i32, ptr @g_node_id, align 4, !tbaa !11
  %14 = zext i32 %13 to i64
  %15 = icmp ne i64 %12, %14
  br i1 %15, label %16, label %22

16:                                               ; preds = %11
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %17)
  %19 = call noundef i64 @_ZN6Thread10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(64) %4)
  %20 = call noundef ptr @_ZN7Message14create_messageE10RemReqType(i32 noundef 0)
  %21 = load i64, ptr %3, align 8, !tbaa !9
  call void @_ZN12MessageQueue7enqueueEmP7Messagem(ptr noundef nonnull align 8 dereferenceable(40) @msg_queue, i64 noundef %19, ptr noundef %20, i64 noundef %21)
  br label %22

22:                                               ; preds = %16, %11
  br label %23

23:                                               ; preds = %22
  %24 = load i64, ptr %3, align 8, !tbaa !9
  %25 = add i64 %24, 1
  store i64 %25, ptr %3, align 8, !tbaa !9
  br label %5, !llvm.loop !13

26:                                               ; preds = %10
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @printf(ptr noundef, ...) #2

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

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

declare noundef ptr @_ZN7Message14create_messageE10RemReqType(i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { 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 #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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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_total_node_cnt = external local_unnamed_addr global i32, align 4
@g_node_id = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@msg_queue = external global %class.MessageQueue, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Thread27send_init_done_to_all_nodesEv(ptr noundef nonnull align 8 dereferenceable(64) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr @g_total_node_cnt, align 4, !tbaa !5
  %.not6 = icmp eq i32 %2, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %.pre7 = load i32, ptr @g_node_id, align 4, !tbaa !5
  br label %.lr.ph

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %10
  %3 = phi i32 [ %11, %10 ], [ %2, %.lr.ph.preheader ]
  %4 = phi i32 [ %12, %10 ], [ %.pre7, %.lr.ph.preheader ]
  %.05 = phi i64 [ %13, %10 ], [ 0, %.lr.ph.preheader ]
  %5 = zext i32 %4 to i64
  %.not = icmp eq i64 %.05, %5
  br i1 %.not, label %10, label %6

6:                                                ; preds = %.lr.ph
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.05)
  %8 = tail call noundef i64 @_ZN6Thread10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  %9 = tail call noundef ptr @_ZN7Message14create_messageE10RemReqType(i32 noundef 0)
  tail call void @_ZN12MessageQueue7enqueueEmP7Messagem(ptr noundef nonnull align 8 dereferenceable(40) @msg_queue, i64 noundef %8, ptr noundef %9, i64 noundef %.05)
  %.pre = load i32, ptr @g_node_id, align 4, !tbaa !5
  %.pre8 = load i32, ptr @g_total_node_cnt, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %.lr.ph, %6
  %11 = phi i32 [ %3, %.lr.ph ], [ %.pre8, %6 ]
  %12 = phi i32 [ %4, %.lr.ph ], [ %.pre, %6 ]
  %13 = add nuw nsw i64 %.05, 1
  %14 = zext i32 %11 to i64
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN6Thread10get_thd_idEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #3 align 2

declare noundef ptr @_ZN7Message14create_messageE10RemReqType(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 = { nofree 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 #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" }
attributes #3 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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