; LLVM IR from JanaSabuj/cppdump :: SegmentTree/segtree.ll (Z5queryxxxxxPxS_)

; 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: 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 i64 @_Z5queryxxxxxPxS_(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store i64 %0, ptr %9, align 8, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !5
  store i64 %3, ptr %12, align 8, !tbaa !5
  store i64 %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !9
  %18 = load i64, ptr %13, align 8, !tbaa !5
  %19 = load i64, ptr %12, align 8, !tbaa !5
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %7
  store i64 0, ptr %8, align 8
  br label %74

22:                                               ; preds = %7
  %23 = load i64, ptr %13, align 8, !tbaa !5
  %24 = load i64, ptr %10, align 8, !tbaa !5
  %25 = icmp slt i64 %23, %24
  br i1 %25, label %30, label %26

26:                                               ; preds = %22
  %27 = load i64, ptr %12, align 8, !tbaa !5
  %28 = load i64, ptr %11, align 8, !tbaa !5
  %29 = icmp sgt i64 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %26, %22
  store i64 0, ptr %8, align 8
  br label %74

31:                                               ; preds = %26
  %32 = load i64, ptr %12, align 8, !tbaa !5
  %33 = load i64, ptr %10, align 8, !tbaa !5
  %34 = icmp eq i64 %32, %33
  br i1 %34, label %35, label %44

35:                                               ; preds = %31
  %36 = load i64, ptr %13, align 8, !tbaa !5
  %37 = load i64, ptr %11, align 8, !tbaa !5
  %38 = icmp eq i64 %36, %37
  br i1 %38, label %39, label %44

39:                                               ; preds = %35
  %40 = load ptr, ptr %14, align 8, !tbaa !9
  %41 = load i64, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds i64, ptr %40, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !5
  store i64 %43, ptr %8, align 8
  br label %74

44:                                               ; preds = %35, %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %45 = load i64, ptr %10, align 8, !tbaa !5
  %46 = load i64, ptr %11, align 8, !tbaa !5
  %47 = add nsw i64 %45, %46
  %48 = sdiv i64 %47, 2
  store i64 %48, ptr %16, align 8, !tbaa !5
  %49 = load i64, ptr %9, align 8, !tbaa !5
  %50 = mul nsw i64 %49, 2
  %51 = load i64, ptr %10, align 8, !tbaa !5
  %52 = load i64, ptr %16, align 8, !tbaa !5
  %53 = load i64, ptr %12, align 8, !tbaa !5
  %54 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef nonnull align 8 dereferenceable(8) %16)
  %55 = load i64, ptr %54, align 8, !tbaa !5
  %56 = load ptr, ptr %14, align 8, !tbaa !9
  %57 = load ptr, ptr %15, align 8, !tbaa !9
  %58 = call noundef i64 @_Z5queryxxxxxPxS_(i64 noundef %50, i64 noundef %51, i64 noundef %52, i64 noundef %53, i64 noundef %55, ptr noundef %56, ptr noundef %57)
  %59 = load i64, ptr %9, align 8, !tbaa !5
  %60 = mul nsw i64 %59, 2
  %61 = add nsw i64 %60, 1
  %62 = load i64, ptr %16, align 8, !tbaa !5
  %63 = add nsw i64 %62, 1
  %64 = load i64, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %65 = load i64, ptr %16, align 8, !tbaa !5
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %17, align 8, !tbaa !5
  %67 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %17, ptr noundef nonnull align 8 dereferenceable(8) %12)
  %68 = load i64, ptr %67, align 8, !tbaa !5
  %69 = load i64, ptr %13, align 8, !tbaa !5
  %70 = load ptr, ptr %14, align 8, !tbaa !9
  %71 = load ptr, ptr %15, align 8, !tbaa !9
  %72 = call noundef i64 @_Z5queryxxxxxPxS_(i64 noundef %61, i64 noundef %63, i64 noundef %64, i64 noundef %68, i64 noundef %69, ptr noundef %70, ptr noundef %71)
  %73 = add nsw i64 %58, %72
  store i64 %73, ptr %8, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %74

74:                                               ; preds = %44, %39, %30, %21
  %75 = load i64, ptr %8, align 8
  ret i64 %75
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

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 = { 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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 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: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5queryxxxxxPxS_(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #1 {
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i64 %3, ptr %8, align 8, !tbaa !5
  store i64 %4, ptr %9, align 8, !tbaa !5
  %12 = icmp slt i64 %4, %3
  br i1 %12, label %37, label %13

13:                                               ; preds = %7
  %14 = icmp slt i64 %4, %1
  %15 = icmp sgt i64 %3, %2
  %or.cond = or i1 %15, %14
  br i1 %or.cond, label %37, label %16

16:                                               ; preds = %13
  %17 = icmp eq i64 %3, %1
  %18 = icmp eq i64 %4, %2
  %or.cond20 = and i1 %17, %18
  br i1 %or.cond20, label %19, label %22

19:                                               ; preds = %16
  %20 = getelementptr inbounds i64, ptr %5, i64 %0
  %21 = load i64, ptr %20, align 8, !tbaa !5
  br label %37

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #3
  %23 = add nsw i64 %2, %1
  %24 = sdiv i64 %23, 2
  store i64 %24, ptr %10, align 8, !tbaa !5
  %25 = shl nsw i64 %0, 1
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = call noundef i64 @_Z5queryxxxxxPxS_(i64 noundef %25, i64 noundef %1, i64 noundef %24, i64 noundef %3, i64 noundef %27, ptr noundef %5, ptr noundef %6)
  %29 = or disjoint i64 %25, 1
  %30 = load i64, ptr %10, align 8, !tbaa !5
  %31 = add nsw i64 %30, 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #3
  store i64 %31, ptr %11, align 8, !tbaa !5
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %11, ptr noundef nonnull align 8 dereferenceable(8) %8)
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = load i64, ptr %9, align 8, !tbaa !5
  %35 = call noundef i64 @_Z5queryxxxxxPxS_(i64 noundef %29, i64 noundef %31, i64 noundef %2, i64 noundef %33, i64 noundef %34, ptr noundef %5, ptr noundef %6)
  %36 = add nsw i64 %35, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #3
  br label %37

37:                                               ; preds = %13, %7, %22, %19
  %.0 = phi i64 [ %21, %19 ], [ %36, %22 ], [ 0, %7 ], [ 0, %13 ]
  ret i64 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass