; LLVM IR from ADJA/algos :: DataStructures/ImplicitSegmentTree.ll (Z3addP4Nodeiiiix)

; 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 { i64, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addP4Nodeiiiix(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i64 noundef %5) #0 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  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 i64 %5, ptr %12, align 8, !tbaa !11
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp sgt i32 %16, %17
  br i1 %18, label %27, label %19

19:                                               ; preds = %6
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %27, label %23

23:                                               ; preds = %19
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp sgt i32 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %23, %19, %6
  br label %92

28:                                               ; preds = %23
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %32, label %42

32:                                               ; preds = %28
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %32
  %37 = load i64, ptr %12, align 8, !tbaa !11
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Node, ptr %38, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !13
  %41 = add nsw i64 %40, %37
  store i64 %41, ptr %39, align 8, !tbaa !13
  br label %92

42:                                               ; preds = %32, %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = add nsw i32 %43, %44
  %46 = ashr i32 %45, 1
  store i32 %46, ptr %13, align 4, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Node, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = icmp eq ptr %49, null
  br i1 %50, label %51, label %60

51:                                               ; preds = %42
  %52 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  invoke void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %52)
          to label %53 unwind label %56

53:                                               ; preds = %51
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 1
  store ptr %52, ptr %55, align 8, !tbaa !15
  br label %60

56:                                               ; preds = %51
  %57 = landingpad { ptr, i32 }
          cleanup
  %58 = extractvalue { ptr, i32 } %57, 0
  store ptr %58, ptr %14, align 8
  %59 = extractvalue { ptr, i32 } %57, 1
  store i32 %59, ptr %15, align 4
  call void @_ZdlPvm(ptr noundef %52, i64 noundef 24) #7
  br label %93

60:                                               ; preds = %53, %42
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Node, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = icmp eq ptr %63, null
  br i1 %64, label %65, label %74

65:                                               ; preds = %60
  %66 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  invoke void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %66)
          to label %67 unwind label %70

67:                                               ; preds = %65
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Node, ptr %68, i32 0, i32 2
  store ptr %66, ptr %69, align 8, !tbaa !16
  br label %74

70:                                               ; preds = %65
  %71 = landingpad { ptr, i32 }
          cleanup
  %72 = extractvalue { ptr, i32 } %71, 0
  store ptr %72, ptr %14, align 8
  %73 = extractvalue { ptr, i32 } %71, 1
  store i32 %73, ptr %15, align 4
  call void @_ZdlPvm(ptr noundef %66, i64 noundef 24) #7
  br label %93

74:                                               ; preds = %67, %60
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Node, ptr %75, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = load i32, ptr %10, align 4, !tbaa !9
  %81 = load i32, ptr %11, align 4, !tbaa !9
  %82 = load i64, ptr %12, align 8, !tbaa !11
  call void @_Z3addP4Nodeiiiix(ptr noundef %77, i32 noundef %78, i32 noundef %79, i32 noundef %80, i32 noundef %81, i64 noundef %82)
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Node, ptr %83, i32 0, i32 2
  %85 = load ptr, ptr %84, align 8, !tbaa !16
  %86 = load i32, ptr %13, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = load i32, ptr %10, align 4, !tbaa !9
  %90 = load i32, ptr %11, align 4, !tbaa !9
  %91 = load i64, ptr %12, align 8, !tbaa !11
  call void @_Z3addP4Nodeiiiix(ptr noundef %85, i32 noundef %87, i32 noundef %88, i32 noundef %89, i32 noundef %90, i64 noundef %91)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %92

92:                                               ; preds = %74, %36, %27
  ret void

93:                                               ; preds = %70, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %94

94:                                               ; preds = %93
  %95 = load ptr, ptr %14, align 8
  %96 = load i32, ptr %15, align 4
  %97 = insertvalue { ptr, i32 } poison, ptr %95, 0
  %98 = insertvalue { ptr, i32 } %97, i32 %96, 1
  resume { ptr, i32 } %98
}

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

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

declare i32 @__gxx_personality_v0(...)

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin allocsize(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 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTS4Node", !12, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !6, i64 16}


; 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 @_Z3addP4Nodeiiiix(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i64 noundef %5) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %invariant.smin = tail call i32 @llvm.smin.i32(i32 %2, i32 %4)
  %7 = icmp sgt i32 %3, %2
  %or.cond41 = icmp slt i32 %invariant.smin, %1
  %or.cond3342 = or i1 %7, %or.cond41
  br i1 %or.cond3342, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %.not32 = icmp sgt i32 %2, %4
  br i1 %.not32, label %.lr.ph.split.us.split, label %.lr.ph.split.split

.lr.ph.split.us.split:                            ; preds = %.lr.ph, %tailrecurse.us
  %.tr3544.us = phi i32 [ %24, %tailrecurse.us ], [ %1, %.lr.ph ]
  %.tr43.us = phi ptr [ %23, %tailrecurse.us ], [ %0, %.lr.ph ]
  %8 = add nsw i32 %.tr3544.us, %2
  %9 = ashr i32 %8, 1
  %10 = getelementptr inbounds i8, ptr %.tr43.us, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %.lr.ph.split.us.split
  %14 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #4
  tail call void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %14)
  store ptr %14, ptr %10, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %13, %.lr.ph.split.us.split
  %16 = phi ptr [ %14, %13 ], [ %11, %.lr.ph.split.us.split ]
  %17 = getelementptr inbounds i8, ptr %.tr43.us, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %tailrecurse.us

20:                                               ; preds = %15
  %21 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #4
  tail call void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %21)
  store ptr %21, ptr %17, align 8, !tbaa !11
  %.pre52 = load ptr, ptr %10, align 8, !tbaa !5
  br label %tailrecurse.us

tailrecurse.us:                                   ; preds = %20, %15
  %22 = phi ptr [ %.pre52, %20 ], [ %16, %15 ]
  tail call void @_Z3addP4Nodeiiiix(ptr noundef %22, i32 noundef %.tr3544.us, i32 noundef %9, i32 noundef %3, i32 noundef %4, i64 noundef %5)
  %23 = load ptr, ptr %17, align 8, !tbaa !11
  %24 = add nsw i32 %9, 1
  %or.cond.us.not = icmp slt i32 %9, %invariant.smin
  br i1 %or.cond.us.not, label %.lr.ph.split.us.split, label %.loopexit

.lr.ph.split.split:                               ; preds = %.lr.ph, %tailrecurse
  %.tr3544 = phi i32 [ %44, %tailrecurse ], [ %1, %.lr.ph ]
  %.tr43 = phi ptr [ %43, %tailrecurse ], [ %0, %.lr.ph ]
  %.not = icmp slt i32 %.tr3544, %3
  br i1 %.not, label %27, label %.split.us

.split.us:                                        ; preds = %.lr.ph.split.split
  %25 = load i64, ptr %.tr43, align 8, !tbaa !12
  %26 = add nsw i64 %25, %5
  store i64 %26, ptr %.tr43, align 8, !tbaa !12
  br label %.loopexit

27:                                               ; preds = %.lr.ph.split.split
  %28 = add nsw i32 %.tr3544, %2
  %29 = ashr i32 %28, 1
  %30 = getelementptr inbounds i8, ptr %.tr43, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %35

33:                                               ; preds = %27
  %34 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #4
  tail call void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %34)
  store ptr %34, ptr %30, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %33, %27
  %36 = phi ptr [ %34, %33 ], [ %31, %27 ]
  %37 = getelementptr inbounds i8, ptr %.tr43, i64 16
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %tailrecurse

40:                                               ; preds = %35
  %41 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #4
  tail call void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %41)
  store ptr %41, ptr %37, align 8, !tbaa !11
  %.pre = load ptr, ptr %30, align 8, !tbaa !5
  br label %tailrecurse

tailrecurse:                                      ; preds = %40, %35
  %42 = phi ptr [ %.pre, %40 ], [ %36, %35 ]
  tail call void @_Z3addP4Nodeiiiix(ptr noundef %42, i32 noundef %.tr3544, i32 noundef %29, i32 noundef %3, i32 noundef %4, i64 noundef %5)
  %43 = load ptr, ptr %37, align 8, !tbaa !11
  %44 = add nsw i32 %29, 1
  %or.cond.not = icmp slt i32 %29, %invariant.smin
  br i1 %or.cond.not, label %.lr.ph.split.split, label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %tailrecurse.us, %6, %.split.us
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

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 = { nobuiltin allocsize(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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { builtin allocsize(0) }

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


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