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

; 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.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 @_ZN5SimTK22Parallel2DExecutorImpl4initEi(ptr noundef nonnull align 8 dereferenceable(57) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 2
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %30

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %18, %12
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = shl i32 1, %14
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %21

18:                                               ; preds = %13
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %6, align 4, !tbaa !9
  br label %13, !llvm.loop !11

21:                                               ; preds = %13
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %6, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = shl i32 1, %24
  store i32 %25, ptr %5, align 4, !tbaa !9
  %26 = getelementptr inbounds %"class.SimTK::Parallel2DExecutorImpl", ptr %8, i32 0, i32 2
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  call void @_ZN5SimTK6Array_INS0_ISt4pairIiiEjEEjE6resizeEj(ptr noundef nonnull align 8 dereferenceable(16) %26, i32 noundef %28)
  %29 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN5SimTK22Parallel2DExecutorImpl11addTriangleEiiii(ptr noundef nonnull align 8 dereferenceable(57) %8, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef %29)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %30

30:                                               ; preds = %21, %11
  %31 = getelementptr inbounds %"class.SimTK::Parallel2DExecutorImpl", ptr %8, i32 0, i32 3
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  call void @_ZN5SimTK6Array_IijE6resizeEj(ptr noundef nonnull align 8 dereferenceable(16) %31, i32 noundef %33)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %54, %30
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %57

39:                                               ; preds = %34
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = getelementptr inbounds %"class.SimTK::Parallel2DExecutorImpl", ptr %8, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = mul nsw i32 %40, %42
  %44 = sitofp i32 %43 to double
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = sitofp i32 %45 to double
  %47 = fdiv double %44, %46
  %48 = fadd double 5.000000e-01, %47
  %49 = call double @llvm.floor.f64(double %48)
  %50 = fptosi double %49 to i32
  %51 = getelementptr inbounds %"class.SimTK::Parallel2DExecutorImpl", ptr %8, i32 0, i32 3
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5SimTK6Array_IijEixEj(ptr noundef nonnull align 8 dereferenceable(16) %51, i32 noundef %52)
  store i32 %50, ptr %53, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %39
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %7, align 4, !tbaa !9
  br label %34, !llvm.loop !23

57:                                               ; preds = %38
  %58 = getelementptr inbounds %"class.SimTK::Parallel2DExecutorImpl", ptr %8, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !13
  %60 = getelementptr inbounds %"class.SimTK::Parallel2DExecutorImpl", ptr %8, i32 0, i32 3
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5SimTK6Array_IijEixEj(ptr noundef nonnull align 8 dereferenceable(16) %60, i32 noundef %61)
  store i32 %59, ptr %62, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5SimTK22Parallel2DExecutorImpl11addTriangleEiiii(ptr noundef nonnull align 8 dereferenceable(57), i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1 align 2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #2

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN5SimTK6Array_IijEixEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 12}
!14 = !{!"_ZTSN5SimTK22Parallel2DExecutorImplE", !15, i64 0, !10, i64 12, !16, i64 16, !19, i64 32, !6, i64 48, !22, i64 56}
!15 = !{!"_ZTSN5SimTK19PIMPLImplementationINS_18Parallel2DExecutorENS_22Parallel2DExecutorImplEEE", !6, i64 0, !10, i64 8}
!16 = !{!"_ZTSN5SimTK6Array_INS0_ISt4pairIiiEjEEjEE", !17, i64 0}
!17 = !{!"_ZTSN5SimTK10ArrayView_INS_6Array_ISt4pairIiiEjEEjEE", !18, i64 0}
!18 = !{!"_ZTSN5SimTK15ArrayViewConst_INS_6Array_ISt4pairIiiEjEEjEE", !6, i64 0, !10, i64 8, !10, i64 12}
!19 = !{!"_ZTSN5SimTK6Array_IijEE", !20, i64 0}
!20 = !{!"_ZTSN5SimTK10ArrayView_IijEE", !21, i64 0}
!21 = !{!"_ZTSN5SimTK15ArrayViewConst_IijEE", !6, i64 0, !10, i64 8, !10, i64 12}
!22 = !{!"bool", !7, i64 0}
!23 = distinct !{!23, !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 uwtable
define dso_local void @_ZN5SimTK22Parallel2DExecutorImpl4initEi(ptr noundef nonnull align 8 dereferenceable(57) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = icmp slt i32 %1, 2
  br i1 %3, label %.thread, label %.preheader

.thread:                                          ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @_ZN5SimTK6Array_IijE6resizeEj(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef 2)
  br label %.lr.ph

.preheader:                                       ; preds = %2, %.preheader
  %.016 = phi i32 [ %7, %.preheader ], [ 1, %2 ]
  %5 = shl nuw i32 1, %.016
  %6 = icmp slt i32 %5, %1
  %7 = add nuw nsw i32 %.016, 1
  br i1 %6, label %.preheader, label %8, !llvm.loop !5

8:                                                ; preds = %.preheader
  %9 = shl nuw i32 2, %.016
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = add nsw i32 %9, -1
  tail call void @_ZN5SimTK6Array_INS0_ISt4pairIiiEjEEjE6resizeEj(ptr noundef nonnull align 8 dereferenceable(16) %10, i32 noundef %11)
  tail call void @_ZN5SimTK22Parallel2DExecutorImpl11addTriangleEiiii(ptr noundef nonnull align 8 dereferenceable(57) %0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef %7)
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = or disjoint i32 %9, 1
  tail call void @_ZN5SimTK6Array_IijE6resizeEj(ptr noundef nonnull align 8 dereferenceable(16) %12, i32 noundef %13)
  %14 = icmp sgt i32 %9, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.thread, %8
  %15 = phi ptr [ %4, %.thread ], [ %12, %8 ]
  %.01721 = phi i32 [ 1, %.thread ], [ %9, %8 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 12
  %17 = uitofp nneg i32 %.01721 to double
  br label %22

._crit_edge:                                      ; preds = %22, %8
  %18 = phi ptr [ %12, %8 ], [ %15, %22 ]
  %.01722 = phi i32 [ %9, %8 ], [ %.01721, %22 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 12
  %20 = load i32, ptr %19, align 4, !tbaa !7
  %21 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5SimTK6Array_IijEixEj(ptr noundef nonnull align 8 dereferenceable(16) %18, i32 noundef %.01722)
  store i32 %20, ptr %21, align 4, !tbaa !21
  ret void

22:                                               ; preds = %.lr.ph, %22
  %.019 = phi i32 [ 0, %.lr.ph ], [ %31, %22 ]
  %23 = load i32, ptr %16, align 4, !tbaa !7
  %24 = mul nsw i32 %23, %.019
  %25 = sitofp i32 %24 to double
  %26 = fdiv double %25, %17
  %27 = fadd double %26, 5.000000e-01
  %28 = tail call double @llvm.floor.f64(double %27)
  %29 = fptosi double %28 to i32
  %30 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5SimTK6Array_IijEixEj(ptr noundef nonnull align 8 dereferenceable(16) %15, i32 noundef %.019)
  store i32 %29, ptr %30, align 4, !tbaa !21
  %31 = add nuw nsw i32 %.019, 1
  %exitcond.not = icmp eq i32 %31, %.01721
  br i1 %exitcond.not, label %._crit_edge, label %22, !llvm.loop !22
}

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

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #1

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN5SimTK6Array_IijEixEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2 align 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !13, i64 12}
!8 = !{!"_ZTSN5SimTK22Parallel2DExecutorImplE", !9, i64 0, !13, i64 12, !14, i64 16, !17, i64 32, !10, i64 48, !20, i64 56}
!9 = !{!"_ZTSN5SimTK19PIMPLImplementationINS_18Parallel2DExecutorENS_22Parallel2DExecutorImplEEE", !10, i64 0, !13, i64 8}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"int", !11, i64 0}
!14 = !{!"_ZTSN5SimTK6Array_INS0_ISt4pairIiiEjEEjEE", !15, i64 0}
!15 = !{!"_ZTSN5SimTK10ArrayView_INS_6Array_ISt4pairIiiEjEEjEE", !16, i64 0}
!16 = !{!"_ZTSN5SimTK15ArrayViewConst_INS_6Array_ISt4pairIiiEjEEjEE", !10, i64 0, !13, i64 8, !13, i64 12}
!17 = !{!"_ZTSN5SimTK6Array_IijEE", !18, i64 0}
!18 = !{!"_ZTSN5SimTK10ArrayView_IijEE", !19, i64 0}
!19 = !{!"_ZTSN5SimTK15ArrayViewConst_IijEE", !10, i64 0, !13, i64 8, !13, i64 12}
!20 = !{!"bool", !11, i64 0}
!21 = !{!13, !13, i64 0}
!22 = distinct !{!22, !6}


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