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

; 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 nounwind uwtable
declare dso_local noundef i32 @_ZNK5boost3mpi6detail16computation_tree11level_indexEi(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK5boost3mpi6detail16computation_tree11child_beginEv(ptr noundef nonnull align 4 dereferenceable(20) %0) #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %8 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 1
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = add nsw i32 %9, %11
  %13 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 2
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = sub nsw i32 %12, %14
  %16 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %18 = srem i32 %15, %17
  store i32 %18, ptr %4, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %19 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 4
  %20 = load i32, ptr %19, align 4, !tbaa !15
  %21 = add nsw i32 %20, 1
  %22 = call noundef i32 @_ZNK5boost3mpi6detail16computation_tree11level_indexEi(ptr noundef nonnull align 4 dereferenceable(20) %7, i32 noundef %21)
  %23 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = load i32, ptr %4, align 4, !tbaa !14
  %26 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 4
  %27 = load i32, ptr %26, align 4, !tbaa !15
  %28 = call noundef i32 @_ZNK5boost3mpi6detail16computation_tree11level_indexEi(ptr noundef nonnull align 4 dereferenceable(20) %7, i32 noundef %27)
  %29 = sub nsw i32 %25, %28
  %30 = mul nsw i32 %24, %29
  %31 = add nsw i32 %22, %30
  store i32 %31, ptr %5, align 4, !tbaa !14
  %32 = load i32, ptr %5, align 4, !tbaa !14
  %33 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !12
  %35 = icmp sge i32 %32, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %1
  %37 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 2
  %38 = load i32, ptr %37, align 4, !tbaa !13
  store i32 %38, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %47

39:                                               ; preds = %1
  %40 = load i32, ptr %5, align 4, !tbaa !14
  %41 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = add nsw i32 %40, %42
  %44 = getelementptr inbounds %"class.boost::mpi::detail::computation_tree", ptr %7, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !12
  %46 = srem i32 %43, %45
  store i32 %46, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %47

47:                                               ; preds = %39, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %48 = load i32, ptr %2, align 4
  ret i32 %48
}

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


; 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 nounwind uwtable
declare dso_local noundef i32 @_ZNK5boost3mpi6detail16computation_tree11level_indexEi(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK5boost3mpi6detail16computation_tree11child_beginEv(ptr noundef nonnull align 4 dereferenceable(20) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr %0, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !10
  %5 = add nsw i32 %4, %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = sub i32 %5, %7
  %9 = srem i32 %8, %4
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = add nsw i32 %11, 1
  %13 = tail call noundef i32 @_ZNK5boost3mpi6detail16computation_tree11level_indexEi(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %12)
  %14 = getelementptr inbounds i8, ptr %0, i64 12
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = load i32, ptr %10, align 4, !tbaa !12
  %17 = tail call noundef i32 @_ZNK5boost3mpi6detail16computation_tree11level_indexEi(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %16)
  %18 = sub nsw i32 %9, %17
  %19 = mul nsw i32 %18, %15
  %20 = add nsw i32 %19, %13
  %21 = load i32, ptr %3, align 4, !tbaa !10
  %.not = icmp slt i32 %20, %21
  %22 = load i32, ptr %6, align 4, !tbaa !11
  br i1 %.not, label %23, label %26

23:                                               ; preds = %1
  %24 = add nsw i32 %22, %20
  %25 = srem i32 %24, %21
  br label %26

26:                                               ; preds = %1, %23
  %.0 = phi i32 [ %25, %23 ], [ %22, %1 ]
  ret i32 %.0
}

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

!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 16}
!13 = !{!6, !7, i64 12}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass