; LLVM IR from Dev-XYS/Algorithms :: Heavy-Light-Decomposition.ll (Z9query_sumP4nodeiiii)

; 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, 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 noundef i32 @_Z9query_sumP4nodeiiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %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 i32, align 4
  %13 = 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
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load i32, ptr %10, align 4, !tbaa !9
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %17, label %25

17:                                               ; preds = %5
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = load i32, ptr %11, align 4, !tbaa !9
  %20 = icmp eq i32 %18, %19
  br i1 %20, label %21, label %25

21:                                               ; preds = %17
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.node, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !11
  store i32 %24, ptr %6, align 4
  br label %77

25:                                               ; preds = %17, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = add nsw i32 %26, %27
  %29 = ashr i32 %28, 1
  store i32 %29, ptr %12, align 4, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %33, label %42

33:                                               ; preds = %25
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.node, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = call noundef i32 @_Z9query_sumP4nodeiiii(ptr noundef %36, i32 noundef %37, i32 noundef %38, i32 noundef %39, i32 noundef %40)
  store i32 %41, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %76

42:                                               ; preds = %25
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = icmp sgt i32 %43, %44
  br i1 %45, label %46, label %56

46:                                               ; preds = %42
  %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 !14
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = call noundef i32 @_Z9query_sumP4nodeiiii(ptr noundef %49, i32 noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef %54)
  store i32 %55, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %76

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

76:                                               ; preds = %56, %46, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %77

77:                                               ; preds = %76, %21
  %78 = load i32, ptr %6, align 4
  ret i32 %78
}

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 = { 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, !10, i64 20}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 8}


; 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 nofree nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z9query_sumP4nodeiiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq i32 %1, %3
  %7 = icmp eq i32 %2, %4
  %or.cond496271 = and i1 %7, %6
  br i1 %or.cond496271, label %tailrecurse.outer41._crit_edge, label %.lr.ph.lr.ph

.lr.ph.lr.ph:                                     ; preds = %5, %tailrecurse.outer
  %8 = phi i1 [ true, %tailrecurse.outer ], [ %6, %5 ]
  %.tr39.ph76 = phi i32 [ %32, %tailrecurse.outer ], [ %3, %5 ]
  %.tr38.ph75 = phi i32 [ %.us-phi56, %tailrecurse.outer ], [ %2, %5 ]
  %.tr37.ph74 = phi i32 [ %32, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph73 = phi ptr [ %31, %tailrecurse.outer ], [ %0, %5 ]
  %accumulator.tr.ph72 = phi i32 [ %33, %tailrecurse.outer ], [ 0, %5 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %tailrecurse.outer41
  %9 = phi i1 [ %8, %.lr.ph.lr.ph ], [ %26, %tailrecurse.outer41 ]
  %.tr38.ph4466 = phi i32 [ %.tr38.ph75, %.lr.ph.lr.ph ], [ %.us-phi56, %tailrecurse.outer41 ]
  %.tr37.ph4364 = phi i32 [ %.tr37.ph74, %.lr.ph.lr.ph ], [ %25, %tailrecurse.outer41 ]
  %.tr.ph4263 = phi ptr [ %.tr.ph73, %.lr.ph.lr.ph ], [ %24, %tailrecurse.outer41 ]
  br i1 %9, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %10 = add i32 %.tr38.ph4466, %.tr37.ph4364
  %11 = ashr i32 %10, 1
  %.not.us57 = icmp slt i32 %11, %4
  br i1 %.not.us57, label %.split.us, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph.split.us, %tailrecurse.us
  %12 = phi i32 [ %15, %tailrecurse.us ], [ %11, %.lr.ph.split.us ]
  %.tr50.us58 = phi ptr [ %13, %tailrecurse.us ], [ %.tr.ph4263, %.lr.ph.split.us ]
  %13 = load ptr, ptr %.tr50.us58, align 8, !tbaa !5
  %14 = add i32 %12, %.tr37.ph4364
  %15 = ashr i32 %14, 1
  %.not.us = icmp slt i32 %15, %4
  br i1 %.not.us, label %.split.us, label %tailrecurse.us

tailrecurse.outer41._crit_edge:                   ; preds = %tailrecurse.outer, %tailrecurse.outer41, %tailrecurse, %5
  %accumulator.tr.ph.lcssa = phi i32 [ 0, %5 ], [ %accumulator.tr.ph72, %tailrecurse ], [ %accumulator.tr.ph72, %tailrecurse.outer41 ], [ %33, %tailrecurse.outer ]
  %.tr.lcssa = phi ptr [ %0, %5 ], [ %20, %tailrecurse ], [ %24, %tailrecurse.outer41 ], [ %31, %tailrecurse.outer ]
  %16 = getelementptr inbounds i8, ptr %.tr.lcssa, i64 16
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %accumulator.ret.tr = add nsw i32 %17, %accumulator.tr.ph.lcssa
  ret i32 %accumulator.ret.tr

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr3851 = phi i32 [ %19, %tailrecurse ], [ %.tr38.ph4466, %.lr.ph ]
  %.tr50 = phi ptr [ %20, %tailrecurse ], [ %.tr.ph4263, %.lr.ph ]
  %18 = add i32 %.tr3851, %.tr37.ph4364
  %19 = ashr i32 %18, 1
  %.not = icmp slt i32 %19, %4
  br i1 %.not, label %.split.us, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split
  %20 = load ptr, ptr %.tr50, align 8, !tbaa !5
  %21 = icmp eq i32 %19, %4
  br i1 %21, label %tailrecurse.outer41._crit_edge, label %.lr.ph.split

.split.us:                                        ; preds = %tailrecurse.us, %.lr.ph.split, %.lr.ph.split.us
  %.us-phi = phi i32 [ %11, %.lr.ph.split.us ], [ %19, %.lr.ph.split ], [ %15, %tailrecurse.us ]
  %.us-phi55 = phi ptr [ %.tr.ph4263, %.lr.ph.split.us ], [ %.tr50, %.lr.ph.split ], [ %13, %tailrecurse.us ]
  %.us-phi56 = phi i32 [ %.tr38.ph4466, %.lr.ph.split.us ], [ %.tr3851, %.lr.ph.split ], [ %12, %tailrecurse.us ]
  %22 = icmp slt i32 %.us-phi, %.tr39.ph76
  br i1 %22, label %tailrecurse.outer41, label %tailrecurse.outer

tailrecurse.outer41:                              ; preds = %.split.us
  %23 = getelementptr inbounds i8, ptr %.us-phi55, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = add nsw i32 %.us-phi, 1
  %26 = icmp eq i32 %25, %.tr39.ph76
  %27 = icmp eq i32 %.us-phi56, %4
  %or.cond49 = and i1 %27, %26
  br i1 %or.cond49, label %tailrecurse.outer41._crit_edge, label %.lr.ph

tailrecurse.outer:                                ; preds = %.split.us
  %28 = load ptr, ptr %.us-phi55, align 8, !tbaa !5
  %29 = tail call noundef i32 @_Z9query_sumP4nodeiiii(ptr noundef %28, i32 noundef %.tr37.ph4364, i32 noundef %.us-phi, i32 noundef %.tr39.ph76, i32 noundef %.us-phi)
  %30 = getelementptr inbounds i8, ptr %.us-phi55, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = add nsw i32 %.us-phi, 1
  %33 = add nsw i32 %29, %accumulator.tr.ph72
  %34 = icmp eq i32 %.us-phi56, %4
  br i1 %34, label %tailrecurse.outer41._crit_edge, label %.lr.ph.lr.ph
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 = !{!"_ZTS4node", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 8}


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