; LLVM IR from amritansh22/Data-Structures-and-Algorithms-in-cpp :: Segment_tree.ll (Z10getSumUtilPiiiiii)

; 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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6getMidii(i32 noundef, i32 noundef) #0

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

18:                                               ; preds = %6
  %19 = load i32, ptr %12, align 4, !tbaa !9
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = icmp sge i32 %19, %20
  br i1 %21, label %22, label %28

22:                                               ; preds = %18
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load i32, ptr %13, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %23, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !9
  store i32 %27, ptr %7, align 4
  br label %61

28:                                               ; preds = %18, %6
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %36, label %32

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

36:                                               ; preds = %32, %28
  store i32 0, ptr %7, align 4
  br label %61

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = call noundef i32 @_Z6getMidii(i32 noundef %38, i32 noundef %39)
  store i32 %40, ptr %14, align 4, !tbaa !9
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = load i32, ptr %14, align 4, !tbaa !9
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = mul nsw i32 2, %46
  %48 = add nsw i32 %47, 1
  %49 = call noundef i32 @_Z10getSumUtilPiiiiii(ptr noundef %41, i32 noundef %42, i32 noundef %43, i32 noundef %44, i32 noundef %45, i32 noundef %48)
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i32, ptr %14, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = mul nsw i32 2, %56
  %58 = add nsw i32 %57, 2
  %59 = call noundef i32 @_Z10getSumUtilPiiiiii(ptr noundef %50, i32 noundef %52, i32 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %58)
  %60 = add nsw i32 %49, %59
  store i32 %60, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %61

61:                                               ; preds = %37, %36, %22
  %62 = load i32, ptr %7, align 4
  ret i32 %62
}

; 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

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 = { 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 willreturn memory(argmem: readwrite) }
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}


; 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 noundef i32 @_Z6getMidii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z10getSumUtilPiiiiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %.not28 = icmp slt i32 %4, %2
  %.not38 = icmp sgt i32 %3, %1
  %or.cond39 = or i1 %.not28, %.not38
  br i1 %or.cond39, label %.lr.ph, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %6
  %7 = icmp slt i32 %2, %3
  br i1 %7, label %.loopexit, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %.lr.ph
  br i1 %.not28, label %.lr.ph.split.split.us, label %.lr.ph.split.split

.lr.ph.split.split.us:                            ; preds = %.lr.ph.split
  %8 = icmp sgt i32 %1, %4
  br i1 %8, label %.loopexit, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph.split.split.us, %tailrecurse.us
  %accumulator.tr40.us4550 = phi i32 [ %15, %tailrecurse.us ], [ 0, %.lr.ph.split.split.us ]
  %.tr3041.us49 = phi i32 [ %13, %tailrecurse.us ], [ %1, %.lr.ph.split.split.us ]
  %.tr3442.us4448 = phi i32 [ %14, %tailrecurse.us ], [ %5, %.lr.ph.split.split.us ]
  %9 = tail call noundef i32 @_Z6getMidii(i32 noundef %.tr3041.us49, i32 noundef %2)
  %10 = shl nsw i32 %.tr3442.us4448, 1
  %11 = or disjoint i32 %10, 1
  %12 = tail call noundef i32 @_Z10getSumUtilPiiiiii(ptr noundef %0, i32 noundef %.tr3041.us49, i32 noundef %9, i32 noundef %3, i32 noundef %4, i32 noundef %11)
  %13 = add nsw i32 %9, 1
  %14 = add nsw i32 %10, 2
  %15 = add nsw i32 %12, %accumulator.tr40.us4550
  %.not52 = icmp slt i32 %9, %4
  br i1 %.not52, label %tailrecurse.us, label %.loopexit

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %6
  %accumulator.tr.lcssa = phi i32 [ 0, %6 ], [ %26, %tailrecurse ]
  %.tr34.lcssa = phi i32 [ %5, %6 ], [ %25, %tailrecurse ]
  %16 = sext i32 %.tr34.lcssa to i64
  %17 = getelementptr inbounds i32, ptr %0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  br label %.loopexit

.lr.ph.split.split:                               ; preds = %.lr.ph.split, %tailrecurse
  %.tr3442 = phi i32 [ %25, %tailrecurse ], [ %5, %.lr.ph.split ]
  %.tr3041 = phi i32 [ %24, %tailrecurse ], [ %1, %.lr.ph.split ]
  %accumulator.tr40 = phi i32 [ %26, %tailrecurse ], [ 0, %.lr.ph.split ]
  %19 = icmp sgt i32 %.tr3041, %4
  br i1 %19, label %.loopexit, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split.split
  %20 = tail call noundef i32 @_Z6getMidii(i32 noundef %.tr3041, i32 noundef %2)
  %21 = shl nsw i32 %.tr3442, 1
  %22 = or disjoint i32 %21, 1
  %23 = tail call noundef i32 @_Z10getSumUtilPiiiiii(ptr noundef %0, i32 noundef %.tr3041, i32 noundef %20, i32 noundef %3, i32 noundef %4, i32 noundef %22)
  %24 = add nsw i32 %20, 1
  %25 = add nsw i32 %21, 2
  %26 = add nsw i32 %23, %accumulator.tr40
  %.not = icmp slt i32 %24, %3
  br i1 %.not, label %.lr.ph.split.split, label %tailrecurse._crit_edge

.loopexit:                                        ; preds = %.lr.ph.split.split, %tailrecurse.us, %.lr.ph, %.lr.ph.split.split.us, %tailrecurse._crit_edge
  %accumulator.tr37 = phi i32 [ %accumulator.tr.lcssa, %tailrecurse._crit_edge ], [ 0, %.lr.ph ], [ 0, %.lr.ph.split.split.us ], [ %15, %tailrecurse.us ], [ %accumulator.tr40, %.lr.ph.split.split ]
  %.0 = phi i32 [ %18, %tailrecurse._crit_edge ], [ 0, %.lr.ph ], [ 0, %.lr.ph.split.split.us ], [ 0, %tailrecurse.us ], [ 0, %.lr.ph.split.split ]
  %accumulator.ret.tr = add nsw i32 %.0, %accumulator.tr37
  ret i32 %accumulator.ret.tr
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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