; LLVM IR from simbody/simbody :: SimTKcommon/src/Parallel2DExecutor.ll (ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii)

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

%"struct.std::pair" = type { i32, i32 }
%"class.SimTK::Parallel2DExecutorImpl" = type <{ %"class.SimTK::PIMPLImplementation.base", i32, %"class.SimTK::Array_", %"class.SimTK::Array_.0", ptr, i8, [7 x i8] }>
%"class.SimTK::PIMPLImplementation.base" = type <{ ptr, i32 }>
%"class.SimTK::Array_" = type { %"class.SimTK::ArrayView_" }
%"class.SimTK::ArrayView_" = type { %"class.SimTK::ArrayViewConst_" }
%"class.SimTK::ArrayViewConst_" = type { ptr, i32, i32 }
%"class.SimTK::Array_.0" = type { %"class.SimTK::ArrayView_.1" }
%"class.SimTK::ArrayView_.1" = type { %"class.SimTK::ArrayViewConst_.2" }
%"class.SimTK::ArrayViewConst_.2" = type { ptr, 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 uwtable
define dso_local void @_ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii(ptr noundef nonnull align 8 dereferenceable(57) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 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 %"struct.std::pair", 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
  %12 = load ptr, ptr %6, align 8
  %13 = load i32, ptr %10, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %5
  %16 = getelementptr inbounds %"class.SimTK::Parallel2DExecutorImpl", ptr %12, i32 0, i32 2
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = sub nsw i32 %17, 1
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN5SimTK6Array_INS0_ISt4pairIiiEjEEjEixEj(ptr noundef nonnull align 8 dereferenceable(16) %16, i32 noundef %18)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %11, ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %8)
  call void @_ZN5SimTK6Array_ISt4pairIiiEjE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(16) %19, ptr noundef nonnull align 4 dereferenceable(8) %11)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %65

20:                                               ; preds = %5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = mul nsw i32 2, %21
  %23 = add nsw i32 %22, 0
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = mul nsw i32 2, %24
  %26 = add nsw i32 %25, 1
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = mul nsw i32 2, %27
  %29 = add nsw i32 %28, 1
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = sub nsw i32 %30, 1
  call void @_ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii(ptr noundef nonnull align 8 dereferenceable(57) %12, i32 noundef %23, i32 noundef %26, i32 noundef %29, i32 noundef %31)
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = mul nsw i32 2, %32
  %34 = add nsw i32 %33, 1
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = mul nsw i32 2, %35
  %37 = add nsw i32 %36, 2
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = mul nsw i32 2, %38
  %40 = add nsw i32 %39, 1
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 1
  call void @_ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii(ptr noundef nonnull align 8 dereferenceable(57) %12, i32 noundef %34, i32 noundef %37, i32 noundef %40, i32 noundef %42)
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = mul nsw i32 2, %43
  %45 = add nsw i32 %44, 0
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = mul nsw i32 2, %46
  %48 = add nsw i32 %47, 2
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = mul nsw i32 2, %49
  %51 = add nsw i32 %50, 2
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = sub nsw i32 %52, 1
  call void @_ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii(ptr noundef nonnull align 8 dereferenceable(57) %12, i32 noundef %45, i32 noundef %48, i32 noundef %51, i32 noundef %53)
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = mul nsw i32 2, %54
  %56 = add nsw i32 %55, 1
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = mul nsw i32 2, %57
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = mul nsw i32 2, %60
  %62 = add nsw i32 %61, 2
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = sub nsw i32 %63, 1
  call void @_ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii(ptr noundef nonnull align 8 dereferenceable(57) %12, i32 noundef %56, i32 noundef %59, i32 noundef %62, i32 noundef %64)
  br label %65

65:                                               ; preds = %20, %15
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN5SimTK6Array_INS0_ISt4pairIiiEjEEjEixEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5SimTK6Array_ISt4pairIiiEjE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #3 align 2

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 = { alwaysinline 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 #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 = !{!"int", !7, i64 0}


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

%"struct.std::pair" = type { i32, i32 }

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii(ptr noundef nonnull align 8 dereferenceable(57) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %"struct.std::pair", align 4
  %9 = icmp eq i32 %4, 0
  br i1 %9, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  %.tr11.lcssa = phi i32 [ %2, %5 ], [ %15, %tailrecurse ]
  %.tr10.lcssa = phi i32 [ %1, %5 ], [ %19, %tailrecurse ]
  %.tr12.lcssa = phi i32 [ %3, %5 ], [ %21, %tailrecurse ]
  store i32 %.tr10.lcssa, ptr %6, align 4, !tbaa !5
  store i32 %.tr11.lcssa, ptr %7, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = add nsw i32 %.tr12.lcssa, -1
  %12 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZN5SimTK6Array_INS0_ISt4pairIiiEjEEjEixEj(ptr noundef nonnull align 8 dereferenceable(16) %10, i32 noundef %11)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %8, ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  call void @_ZN5SimTK6Array_ISt4pairIiiEjE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef nonnull align 4 dereferenceable(8) %8)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  ret void

tailrecurse:                                      ; preds = %5, %tailrecurse
  %.tr1317 = phi i32 [ %18, %tailrecurse ], [ %4, %5 ]
  %.tr1216 = phi i32 [ %21, %tailrecurse ], [ %3, %5 ]
  %.tr1115 = phi i32 [ %15, %tailrecurse ], [ %2, %5 ]
  %.tr1014 = phi i32 [ %19, %tailrecurse ], [ %1, %5 ]
  %13 = shl nsw i32 %.tr1014, 1
  %14 = shl nsw i32 %.tr1115, 1
  %15 = or disjoint i32 %14, 1
  %16 = shl nsw i32 %.tr1216, 1
  %17 = or disjoint i32 %16, 1
  %18 = add nsw i32 %.tr1317, -1
  tail call void @_ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii(ptr noundef nonnull align 8 dereferenceable(57) %0, i32 noundef %13, i32 noundef %15, i32 noundef %17, i32 noundef %18)
  %19 = or disjoint i32 %13, 1
  %20 = add nsw i32 %14, 2
  tail call void @_ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii(ptr noundef nonnull align 8 dereferenceable(57) %0, i32 noundef %19, i32 noundef %20, i32 noundef %17, i32 noundef %18)
  %21 = add nsw i32 %16, 2
  tail call void @_ZN5SimTK22Parallel2DExecutorImpl9addSquareEiiii(ptr noundef nonnull align 8 dereferenceable(57) %0, i32 noundef %13, i32 noundef %20, i32 noundef %21, i32 noundef %18)
  %22 = icmp eq i32 %18, 0
  br i1 %22, label %tailrecurse._crit_edge, label %tailrecurse
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN5SimTK6Array_INS0_ISt4pairIiiEjEEjEixEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5SimTK6Array_ISt4pairIiiEjE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #3 align 2

attributes #0 = { mustprogress 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 = { alwaysinline 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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