; LLVM IR from Dev-XYS/Algorithms :: Persistent-Array.ll (Z6modifyRP4nodeS0_iiii)

; 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.node = type <{ ptr, ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4nodenwEm(i64 noundef) #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6modifyRP4nodeS0_iiii(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #3 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  %16 = call noundef ptr @_ZN4nodenwEm(i64 noundef 24)
  invoke void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(20) %16, i32 noundef 0)
          to label %17 unwind label %27

17:                                               ; preds = %6
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %16, ptr %18, align 8, !tbaa !5
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %31

22:                                               ; preds = %17
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.node, ptr %25, i32 0, i32 2
  store i32 %23, ptr %26, align 8, !tbaa !11
  br label %75

27:                                               ; preds = %6
  %28 = landingpad { ptr, i32 }
          cleanup
  %29 = extractvalue { ptr, i32 } %28, 0
  store ptr %29, ptr %13, align 8
  %30 = extractvalue { ptr, i32 } %28, 1
  store i32 %30, ptr %14, align 4
  call void @_ZdlPvm(ptr noundef %16, i64 noundef 24) #4
  br label %76

31:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = add nsw i32 %32, %33
  %35 = ashr i32 %34, 1
  store i32 %35, ptr %15, align 4, !tbaa !9
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = load i32, ptr %15, align 4, !tbaa !9
  %38 = icmp sle i32 %36, %37
  br i1 %38, label %39, label %56

39:                                               ; preds = %31
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.node, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 1
  store ptr %42, ptr %45, align 8, !tbaa !13
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.node, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load i32, ptr %15, align 4, !tbaa !9
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %12, align 4, !tbaa !9
  call void @_Z6modifyRP4nodeS0_iiii(ptr noundef nonnull align 8 dereferenceable(8) %48, ptr noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef %54, i32 noundef %55)
  br label %74

56:                                               ; preds = %31
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.node, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.node, ptr %61, i32 0, i32 0
  store ptr %59, ptr %62, align 8, !tbaa !14
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.node, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  %69 = load i32, ptr %15, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = load i32, ptr %12, align 4, !tbaa !9
  call void @_Z6modifyRP4nodeS0_iiii(ptr noundef nonnull align 8 dereferenceable(8) %65, ptr noundef %68, i32 noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %73)
  br label %74

74:                                               ; preds = %56, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %75

75:                                               ; preds = %74, %22
  ret void

76:                                               ; preds = %27
  %77 = load ptr, ptr %13, align 8
  %78 = load i32, ptr %14, align 4
  %79 = insertvalue { ptr, i32 } poison, ptr %77, 0
  %80 = insertvalue { ptr, i32 } %79, i32 %78, 1
  resume { ptr, i32 } %80
}

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 = { nobuiltin nounwind "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 willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { builtin nounwind }
attributes #5 = { 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 16}
!12 = !{!"_ZTS4node", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, 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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4nodenwEm(i64 noundef) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6modifyRP4nodeS0_iiii(ptr nocapture noundef nonnull align 8 dereferenceable(8) %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %7 = tail call noundef ptr @_ZN4nodenwEm(i64 noundef 24)
  tail call void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(20) %7, i32 noundef 0)
  store ptr %7, ptr %0, align 8, !tbaa !5
  %8 = icmp eq i32 %2, %3
  br i1 %8, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %tailrecurse.outer
  %9 = phi ptr [ %28, %tailrecurse.outer ], [ %7, %6 ]
  %.tr30.ph45 = phi i32 [ %.tr3040, %tailrecurse.outer ], [ %3, %6 ]
  %.tr29.ph44 = phi i32 [ %27, %tailrecurse.outer ], [ %2, %6 ]
  %.tr28.ph43 = phi ptr [ %26, %tailrecurse.outer ], [ %1, %6 ]
  %.tr.ph42 = phi ptr [ %24, %tailrecurse.outer ], [ %0, %6 ]
  br label %11

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %6
  %.lcssa = phi ptr [ %7, %6 ], [ %20, %tailrecurse ], [ %28, %tailrecurse.outer ]
  %10 = getelementptr inbounds i8, ptr %.lcssa, i64 16
  store i32 %5, ptr %10, align 8, !tbaa !9
  ret void

11:                                               ; preds = %.lr.ph, %tailrecurse
  %12 = phi ptr [ %9, %.lr.ph ], [ %20, %tailrecurse ]
  %.tr3040 = phi i32 [ %.tr30.ph45, %.lr.ph ], [ %14, %tailrecurse ]
  %.tr2839 = phi ptr [ %.tr28.ph43, %.lr.ph ], [ %19, %tailrecurse ]
  %.tr38 = phi ptr [ %.tr.ph42, %.lr.ph ], [ %18, %tailrecurse ]
  %13 = add nsw i32 %.tr3040, %.tr29.ph44
  %14 = ashr i32 %13, 1
  %.not = icmp slt i32 %14, %4
  br i1 %.not, label %tailrecurse.outer, label %tailrecurse

tailrecurse:                                      ; preds = %11
  %15 = getelementptr inbounds i8, ptr %.tr2839, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %16, ptr %17, align 8, !tbaa !12
  %18 = load ptr, ptr %.tr38, align 8, !tbaa !5
  %19 = load ptr, ptr %.tr2839, align 8, !tbaa !13
  %20 = tail call noundef ptr @_ZN4nodenwEm(i64 noundef 24)
  tail call void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(20) %20, i32 noundef 0)
  store ptr %20, ptr %18, align 8, !tbaa !5
  %21 = icmp eq i32 %.tr29.ph44, %14
  br i1 %21, label %tailrecurse.outer._crit_edge, label %11

tailrecurse.outer:                                ; preds = %11
  %22 = load ptr, ptr %.tr2839, align 8, !tbaa !13
  store ptr %22, ptr %12, align 8, !tbaa !13
  %23 = load ptr, ptr %.tr38, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = getelementptr inbounds i8, ptr %.tr2839, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = add nsw i32 %14, 1
  %28 = tail call noundef ptr @_ZN4nodenwEm(i64 noundef 24)
  tail call void @_ZN4nodeC2Ei(ptr noundef nonnull align 8 dereferenceable(20) %28, i32 noundef 0)
  store ptr %28, ptr %24, align 8, !tbaa !5
  %29 = icmp eq i32 %27, %.tr3040
  br i1 %29, label %tailrecurse.outer._crit_edge, label %.lr.ph
}

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 0}


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