; LLVM IR from apple/turicreate :: src/external/boost/boost_1_68_0/libs/mpi/src (computation_tree)

; 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.boost::mpi::detail::computation_tree" = type { i32, i32, i32, i32, i32 }

@_ZN5boost3mpi6detail16computation_tree24default_branching_factorE = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5boost3mpi6detail16computation_treeC2Eiiii(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) unnamed_addr #0 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %14 = load ptr, ptr %6, align 8
  %15 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %14, i32 0, i32 0
  %16 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %16, ptr %15, align 4, !tbaa !11
  %17 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %14, i32 0, i32 1
  %18 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %18, ptr %17, align 4, !tbaa !13
  %19 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %14, i32 0, i32 2
  %20 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %20, ptr %19, align 4, !tbaa !14
  %21 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %14, i32 0, i32 3
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = icmp sgt i32 %22, 1
  br i1 %23, label %24, label %26

24:                                               ; preds = %5
  %25 = load i32, ptr %10, align 4, !tbaa !9
  br label %28

26:                                               ; preds = %5
  %27 = load i32, ptr @_ZN5boost3mpi6detail16computation_tree24default_branching_factorE, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %26, %24
  %29 = phi i32 [ %25, %24 ], [ %27, %26 ]
  store i32 %29, ptr %21, align 4, !tbaa !15
  %30 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %14, i32 0, i32 4
  store i32 0, ptr %30, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = add nsw i32 %31, %32
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = sub nsw i32 %33, %34
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = srem i32 %35, %36
  store i32 %37, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 1, ptr %13, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %42, %28
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %42, label %53

42:                                               ; preds = %38
  %43 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %14, i32 0, i32 4
  %44 = load i32, ptr %43, align 4, !tbaa !16
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %43, align 4, !tbaa !16
  %46 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %14, i32 0, i32 3
  %47 = load i32, ptr %46, align 4, !tbaa !15
  %48 = load i32, ptr %13, align 4, !tbaa !9
  %49 = mul nsw i32 %48, %47
  store i32 %49, ptr %13, align 4, !tbaa !9
  %50 = load i32, ptr %13, align 4, !tbaa !9
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = add nsw i32 %51, %50
  store i32 %52, ptr %12, align 4, !tbaa !9
  br label %38, !llvm.loop !17

53:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!12 = !{!"_ZTSN5boost3mpi6detail16computation_treeE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@_ZN5boost3mpi6detail16computation_tree24default_branching_factorE = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(read, argmem: write, inaccessiblemem: none) uwtable
define dso_local void @_ZN5boost3mpi6detail16computation_treeC2Eiiii(ptr nocapture noundef nonnull writeonly align 4 dereferenceable(20) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) unnamed_addr #0 align 2 {
  store i32 %1, ptr %0, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %2, ptr %6, align 4, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %3, ptr %7, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = icmp sgt i32 %4, 1
  %10 = load i32, ptr @_ZN5boost3mpi6detail16computation_tree24default_branching_factorE, align 4
  %11 = select i1 %9, i32 %4, i32 %10
  store i32 %11, ptr %8, align 4, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 0, ptr %12, align 4, !tbaa !13
  %13 = add nsw i32 %2, %1
  %14 = sub i32 %13, %3
  %15 = srem i32 %14, %2
  %.not15 = icmp slt i32 %15, 0
  br i1 %.not15, label %20, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.017 = phi i32 [ %18, %.lr.ph ], [ 1, %5 ]
  %.01416 = phi i32 [ %19, %.lr.ph ], [ 0, %5 ]
  %16 = phi i32 [ %17, %.lr.ph ], [ 0, %5 ]
  %17 = add nuw nsw i32 %16, 1
  %18 = mul nsw i32 %.017, %11
  %19 = add nsw i32 %18, %.01416
  %.not = icmp sgt i32 %19, %15
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph
  store i32 %17, ptr %12, align 4, !tbaa !13
  br label %20

20:                                               ; preds = %._crit_edge, %5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: write, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"_ZTSN5boost3mpi6detail16computation_treeE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 12}
!13 = !{!6, !7, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass