; LLVM IR from microsoft/Multiverso :: src/net/allreduce_engine.ll (ZN10multiverso15AllreduceEngine9AllgatherEPciS1_)

; 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.multiverso::AllreduceEngine" = type <{ i32, i32, ptr, %"class.multiverso::BruckMap", %"class.multiverso::RecursiveHalvingMap", ptr, ptr, ptr, i32, [4 x i8] }>
%"class.multiverso::BruckMap" = type { i32, %"class.std::vector", %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.multiverso::RecursiveHalvingMap" = type { i32, i32, i32, %"class.std::vector", %"class.std::vector", %"class.std::vector", %"class.std::vector", %"class.std::vector" }

; 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 void @_ZN10multiverso15AllreduceEngine9AllgatherEPciPiS2_S1_(ptr noundef nonnull align 8 dereferenceable(236), ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10multiverso15AllreduceEngine9AllgatherEPciS1_(ptr noundef nonnull align 8 dereferenceable(236) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  %11 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 5
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds i32, ptr %12, i64 0
  store i32 0, ptr %13, align 4, !tbaa !9
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 6
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %17 = getelementptr inbounds i32, ptr %16, i64 0
  store i32 %14, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %51, %4
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !21
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %54

24:                                               ; preds = %18
  %25 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 5
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %26, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 6
  %33 = load ptr, ptr %32, align 8, !tbaa !20
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = sub nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %33, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = add nsw i32 %31, %38
  %40 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 5
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  store i32 %39, ptr %44, align 4, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 6
  %47 = load ptr, ptr %46, align 8, !tbaa !20
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  store i32 %45, ptr %50, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %24
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !22

54:                                               ; preds = %23
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !21
  %59 = mul nsw i32 %56, %58
  %60 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 5
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = getelementptr inbounds %"class.multiverso::AllreduceEngine", ptr %10, i32 0, i32 6
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN10multiverso15AllreduceEngine9AllgatherEPciPiS2_S1_(ptr noundef nonnull align 8 dereferenceable(236) %10, ptr noundef %55, i32 noundef %59, ptr noundef %61, ptr noundef %63, ptr noundef %64)
  ret void
}

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 = { 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, !6, i64 208}
!12 = !{!"_ZTSN10multiverso15AllreduceEngineE", !10, i64 0, !10, i64 4, !6, i64 8, !13, i64 16, !18, i64 72, !6, i64 208, !6, i64 216, !6, i64 224, !10, i64 232}
!13 = !{!"_ZTSN10multiverso8BruckMapE", !10, i64 0, !14, i64 8, !14, i64 32}
!14 = !{!"_ZTSSt6vectorIiSaIiEE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!"_ZTSN10multiverso19RecursiveHalvingMapE", !10, i64 0, !19, i64 4, !10, i64 8, !14, i64 16, !14, i64 40, !14, i64 64, !14, i64 88, !14, i64 112}
!19 = !{!"_ZTSN10multiverso24RecursiveHalvingNodeTypeE", !7, i64 0}
!20 = !{!12, !6, i64 216}
!21 = !{!12, !10, 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"

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10multiverso15AllreduceEngine9AllgatherEPciPiS2_S1_(ptr noundef nonnull align 8 dereferenceable(236), ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10multiverso15AllreduceEngine9AllgatherEPciS1_(ptr noundef nonnull align 8 dereferenceable(236) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 208
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !18
  %7 = getelementptr inbounds i8, ptr %0, i64 216
  %8 = load ptr, ptr %7, align 8, !tbaa !19
  store i32 %2, ptr %8, align 4, !tbaa !18
  %9 = load i32, ptr %0, align 8, !tbaa !20
  %10 = icmp sgt i32 %9, 1
  br i1 %10, label %.lr.ph.lver.check, label %._crit_edge

.lr.ph.lver.check:                                ; preds = %4
  %invariant.gep = getelementptr i8, ptr %6, i64 -4
  %scevgep = getelementptr i8, ptr %6, i64 8589934588
  %scevgep17 = getelementptr i8, ptr %8, i64 4
  %scevgep18 = getelementptr i8, ptr %8, i64 8589934588
  %bound0 = icmp ult ptr %6, %scevgep18
  %bound1 = icmp ult ptr %scevgep17, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.lver.orig, label %.lr.ph.ph

.lr.ph.lver.orig:                                 ; preds = %.lr.ph.lver.check, %.lr.ph.lver.orig
  %indvars.iv.lver.orig = phi i64 [ %indvars.iv.next.lver.orig, %.lr.ph.lver.orig ], [ 1, %.lr.ph.lver.check ]
  %gep.lver.orig = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv.lver.orig
  %11 = load i32, ptr %gep.lver.orig, align 4, !tbaa !18
  %12 = add nsw i32 %11, %2
  %13 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.lver.orig
  store i32 %12, ptr %13, align 4, !tbaa !18
  %14 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv.lver.orig
  store i32 %2, ptr %14, align 4, !tbaa !18
  %indvars.iv.next.lver.orig = add nuw nsw i64 %indvars.iv.lver.orig, 1
  %15 = load i32, ptr %0, align 8, !tbaa !20
  %16 = sext i32 %15 to i64
  %17 = icmp slt i64 %indvars.iv.next.lver.orig, %16
  br i1 %17, label %.lr.ph.lver.orig, label %._crit_edge, !llvm.loop !21

.lr.ph.ph:                                        ; preds = %.lr.ph.lver.check
  %load_initial = load i32, ptr %6, align 4
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph.lver.orig, %4
  %.lcssa = phi i32 [ %9, %4 ], [ %15, %.lr.ph.lver.orig ], [ %22, %.lr.ph ]
  %18 = mul nsw i32 %.lcssa, %2
  tail call void @_ZN10multiverso15AllreduceEngine9AllgatherEPciPiS2_S1_(ptr noundef nonnull align 8 dereferenceable(236) %0, ptr noundef %1, i32 noundef %18, ptr noundef nonnull %6, ptr noundef nonnull %8, ptr noundef %3)
  ret void

.lr.ph:                                           ; preds = %.lr.ph.ph, %.lr.ph
  %store_forwarded = phi i32 [ %load_initial, %.lr.ph.ph ], [ %19, %.lr.ph ]
  %indvars.iv = phi i64 [ 1, %.lr.ph.ph ], [ %indvars.iv.next, %.lr.ph ]
  %19 = add nsw i32 %store_forwarded, %2
  %20 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv
  store i32 %19, ptr %20, align 4, !tbaa !18
  %21 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv
  store i32 %2, ptr %21, align 4, !tbaa !18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = load i32, ptr %0, align 8, !tbaa !20
  %23 = sext i32 %22 to i64
  %24 = icmp slt i64 %indvars.iv.next, %23
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !21
}

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

!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, !10, i64 208}
!6 = !{!"_ZTSN10multiverso15AllreduceEngineE", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !16, i64 72, !10, i64 208, !10, i64 216, !10, i64 224, !7, i64 232}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSN10multiverso8BruckMapE", !7, i64 0, !12, i64 8, !12, i64 32}
!12 = !{!"_ZTSSt6vectorIiSaIiEE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !10, i64 0, !10, i64 8, !10, i64 16}
!16 = !{!"_ZTSN10multiverso19RecursiveHalvingMapE", !7, i64 0, !17, i64 4, !7, i64 8, !12, i64 16, !12, i64 40, !12, i64 64, !12, i64 88, !12, i64 112}
!17 = !{!"_ZTSN10multiverso24RecursiveHalvingNodeTypeE", !8, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!6, !10, i64 216}
!20 = !{!6, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass