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

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9query_maxP4nodeiiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %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
  %14 = alloca i32, align 4
  %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
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %10, align 4, !tbaa !9
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %27

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

23:                                               ; preds = %19
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.node, ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 4, !tbaa !11
  store i32 %26, ptr %6, align 4
  br label %80

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

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

44:                                               ; preds = %27
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %12, align 4, !tbaa !9
  %47 = icmp sgt i32 %45, %46
  br i1 %47, label %48, label %58

48:                                               ; preds = %44
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.node, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = call noundef i32 @_Z9query_maxP4nodeiiii(ptr noundef %51, i32 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56)
  store i32 %57, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %79

58:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.node, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = call noundef i32 @_Z9query_maxP4nodeiiii(ptr noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64, i32 noundef %65)
  store i32 %66, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.node, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !14
  %70 = load i32, ptr %12, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = load i32, ptr %12, align 4, !tbaa !9
  %74 = add nsw i32 %73, 1
  %75 = load i32, ptr %11, align 4, !tbaa !9
  %76 = call noundef i32 @_Z9query_maxP4nodeiiii(ptr noundef %69, i32 noundef %71, i32 noundef %72, i32 noundef %74, i32 noundef %75)
  store i32 %76, ptr %15, align 4, !tbaa !9
  %77 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %15)
  %78 = load i32, ptr %77, align 4, !tbaa !9
  store i32 %78, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  store i32 1, ptr %13, align 4
  br label %79

79:                                               ; preds = %58, %48, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %80

80:                                               ; preds = %79, %23
  %81 = load i32, ptr %6, align 4
  ret i32 %81
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 = { 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 20}
!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 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9query_maxP4nodeiiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = icmp eq i32 %1, %3
  %9 = icmp eq i32 %2, %4
  %or.cond4455 = and i1 %8, %9
  br i1 %or.cond4455, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %tailrecurse.outer
  %10 = phi i1 [ %27, %tailrecurse.outer ], [ %8, %5 ]
  %.tr38.ph59 = phi i32 [ %.us-phi49, %tailrecurse.outer ], [ %2, %5 ]
  %.tr37.ph57 = phi i32 [ %26, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph56 = phi ptr [ %25, %tailrecurse.outer ], [ %0, %5 ]
  br i1 %10, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %11 = add i32 %.tr38.ph59, %.tr37.ph57
  %12 = ashr i32 %11, 1
  %.not.us50 = icmp slt i32 %12, %4
  br i1 %.not.us50, label %.split.us, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph.split.us, %tailrecurse.us
  %13 = phi i32 [ %16, %tailrecurse.us ], [ %12, %.lr.ph.split.us ]
  %.tr45.us51 = phi ptr [ %14, %tailrecurse.us ], [ %.tr.ph56, %.lr.ph.split.us ]
  %14 = load ptr, ptr %.tr45.us51, align 8, !tbaa !5
  %15 = add i32 %13, %.tr37.ph57
  %16 = ashr i32 %15, 1
  %.not.us = icmp slt i32 %16, %4
  br i1 %.not.us, label %.split.us, label %tailrecurse.us

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  %.tr.lcssa = phi ptr [ %0, %5 ], [ %21, %tailrecurse ], [ %25, %tailrecurse.outer ]
  %17 = getelementptr inbounds i8, ptr %.tr.lcssa, i64 20
  %18 = load i32, ptr %17, align 4, !tbaa !11
  br label %common.ret134

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr3846 = phi i32 [ %20, %tailrecurse ], [ %.tr38.ph59, %.lr.ph ]
  %.tr45 = phi ptr [ %21, %tailrecurse ], [ %.tr.ph56, %.lr.ph ]
  %19 = add i32 %.tr3846, %.tr37.ph57
  %20 = ashr i32 %19, 1
  %.not = icmp slt i32 %20, %4
  br i1 %.not, label %.split.us, label %tailrecurse

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

.split.us:                                        ; preds = %tailrecurse.us, %.lr.ph.split, %.lr.ph.split.us
  %.us-phi = phi i32 [ %12, %.lr.ph.split.us ], [ %20, %.lr.ph.split ], [ %16, %tailrecurse.us ]
  %.us-phi48 = phi ptr [ %.tr.ph56, %.lr.ph.split.us ], [ %.tr45, %.lr.ph.split ], [ %14, %tailrecurse.us ]
  %.us-phi49 = phi i32 [ %.tr38.ph59, %.lr.ph.split.us ], [ %.tr3846, %.lr.ph.split ], [ %13, %tailrecurse.us ]
  %23 = icmp slt i32 %.us-phi, %3
  br i1 %23, label %tailrecurse.outer, label %29

tailrecurse.outer:                                ; preds = %.split.us
  %24 = getelementptr inbounds i8, ptr %.us-phi48, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = add nsw i32 %.us-phi, 1
  %27 = icmp eq i32 %26, %3
  %28 = icmp eq i32 %.us-phi49, %4
  %or.cond44 = and i1 %27, %28
  br i1 %or.cond44, label %tailrecurse.outer._crit_edge, label %.lr.ph

common.ret134:                                    ; preds = %29, %tailrecurse.outer._crit_edge
  %common.ret134.op = phi i32 [ %18, %tailrecurse.outer._crit_edge ], [ %37, %29 ]
  ret i32 %common.ret134.op

29:                                               ; preds = %.split.us
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %30 = load ptr, ptr %.us-phi48, align 8, !tbaa !5
  %31 = tail call noundef i32 @_Z9query_maxP4nodeiiii(ptr noundef %30, i32 noundef %.tr37.ph57, i32 noundef %.us-phi, i32 noundef %3, i32 noundef %.us-phi)
  store i32 %31, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %32 = getelementptr inbounds i8, ptr %.us-phi48, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !12
  %34 = add nsw i32 %.us-phi, 1
  %35 = tail call noundef i32 @_Z9query_maxP4nodeiiii(ptr noundef %33, i32 noundef %34, i32 noundef %.us-phi49, i32 noundef %34, i32 noundef %4)
  store i32 %35, ptr %7, align 4, !tbaa !13
  %36 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %37 = load i32, ptr %36, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  br label %common.ret134
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #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 = { 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, !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 20}
!12 = !{!6, !7, i64 8}
!13 = !{!10, !10, i64 0}


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