; LLVM IR from TheAlgorithms/C-Plus-Plus :: range_queries/segtree.ll (Z5queryPSt6vectorIlSaIlEES2_mmmmm)

; 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 nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5queryPSt6vectorIlSaIlEES2_mmmmm(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, i64 noundef %6) #2 {
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !9
  store i64 %3, ptr %12, align 8, !tbaa !9
  store i64 %4, ptr %13, align 8, !tbaa !9
  store i64 %5, ptr %14, align 8, !tbaa !9
  store i64 %6, ptr %15, align 8, !tbaa !9
  %17 = load i64, ptr %13, align 8, !tbaa !9
  %18 = load i64, ptr %14, align 8, !tbaa !9
  %19 = icmp ugt i64 %17, %18
  br i1 %19, label %28, label %20

20:                                               ; preds = %7
  %21 = load i64, ptr %11, align 8, !tbaa !9
  %22 = load i64, ptr %14, align 8, !tbaa !9
  %23 = icmp ugt i64 %21, %22
  br i1 %23, label %28, label %24

24:                                               ; preds = %20
  %25 = load i64, ptr %13, align 8, !tbaa !9
  %26 = load i64, ptr %12, align 8, !tbaa !9
  %27 = icmp ugt i64 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24, %20, %7
  store i64 0, ptr %8, align 8
  br label %120

29:                                               ; preds = %24
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = load i64, ptr %15, align 8, !tbaa !9
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %31) #3
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %80

35:                                               ; preds = %29
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load i64, ptr %15, align 8, !tbaa !9
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %36, i64 noundef %37) #3
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = load i64, ptr %14, align 8, !tbaa !9
  %41 = load i64, ptr %13, align 8, !tbaa !9
  %42 = sub i64 %40, %41
  %43 = add i64 %42, 1
  %44 = mul i64 %39, %43
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load i64, ptr %15, align 8, !tbaa !9
  %47 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %45, i64 noundef %46) #3
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = add i64 %48, %44
  store i64 %49, ptr %47, align 8, !tbaa !9
  %50 = load i64, ptr %13, align 8, !tbaa !9
  %51 = load i64, ptr %14, align 8, !tbaa !9
  %52 = icmp ne i64 %50, %51
  br i1 %52, label %53, label %76

53:                                               ; preds = %35
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = load i64, ptr %15, align 8, !tbaa !9
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %54, i64 noundef %55) #3
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = load i64, ptr %15, align 8, !tbaa !9
  %60 = mul i64 2, %59
  %61 = add i64 %60, 1
  %62 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %58, i64 noundef %61) #3
  %63 = load i64, ptr %62, align 8, !tbaa !9
  %64 = add nsw i64 %63, %57
  store i64 %64, ptr %62, align 8, !tbaa !9
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = load i64, ptr %15, align 8, !tbaa !9
  %67 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %65, i64 noundef %66) #3
  %68 = load i64, ptr %67, align 8, !tbaa !9
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = load i64, ptr %15, align 8, !tbaa !9
  %71 = mul i64 2, %70
  %72 = add i64 %71, 2
  %73 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %69, i64 noundef %72) #3
  %74 = load i64, ptr %73, align 8, !tbaa !9
  %75 = add nsw i64 %74, %68
  store i64 %75, ptr %73, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %53, %35
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load i64, ptr %15, align 8, !tbaa !9
  %79 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %77, i64 noundef %78) #3
  store i64 0, ptr %79, align 8, !tbaa !9
  br label %80

80:                                               ; preds = %76, %29
  %81 = load i64, ptr %11, align 8, !tbaa !9
  %82 = load i64, ptr %13, align 8, !tbaa !9
  %83 = icmp ule i64 %81, %82
  br i1 %83, label %84, label %93

84:                                               ; preds = %80
  %85 = load i64, ptr %12, align 8, !tbaa !9
  %86 = load i64, ptr %14, align 8, !tbaa !9
  %87 = icmp uge i64 %85, %86
  br i1 %87, label %88, label %93

88:                                               ; preds = %84
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = load i64, ptr %15, align 8, !tbaa !9
  %91 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %89, i64 noundef %90) #3
  %92 = load i64, ptr %91, align 8, !tbaa !9
  store i64 %92, ptr %8, align 8
  br label %120

93:                                               ; preds = %84, %80
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %94 = load i64, ptr %13, align 8, !tbaa !9
  %95 = load i64, ptr %14, align 8, !tbaa !9
  %96 = add i64 %94, %95
  %97 = udiv i64 %96, 2
  store i64 %97, ptr %16, align 8, !tbaa !9
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = load ptr, ptr %10, align 8, !tbaa !5
  %100 = load i64, ptr %11, align 8, !tbaa !9
  %101 = load i64, ptr %12, align 8, !tbaa !9
  %102 = load i64, ptr %13, align 8, !tbaa !9
  %103 = load i64, ptr %16, align 8, !tbaa !9
  %104 = load i64, ptr %15, align 8, !tbaa !9
  %105 = mul i64 2, %104
  %106 = add i64 %105, 1
  %107 = call noundef i64 @_Z5queryPSt6vectorIlSaIlEES2_mmmmm(ptr noundef %98, ptr noundef %99, i64 noundef %100, i64 noundef %101, i64 noundef %102, i64 noundef %103, i64 noundef %106)
  %108 = load ptr, ptr %9, align 8, !tbaa !5
  %109 = load ptr, ptr %10, align 8, !tbaa !5
  %110 = load i64, ptr %11, align 8, !tbaa !9
  %111 = load i64, ptr %12, align 8, !tbaa !9
  %112 = load i64, ptr %16, align 8, !tbaa !9
  %113 = add i64 %112, 1
  %114 = load i64, ptr %14, align 8, !tbaa !9
  %115 = load i64, ptr %15, align 8, !tbaa !9
  %116 = mul i64 2, %115
  %117 = add i64 %116, 2
  %118 = call noundef i64 @_Z5queryPSt6vectorIlSaIlEES2_mmmmm(ptr noundef %108, ptr noundef %109, i64 noundef %110, i64 noundef %111, i64 noundef %113, i64 noundef %114, i64 noundef %117)
  %119 = add nsw i64 %107, %118
  store i64 %119, ptr %8, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %120

120:                                              ; preds = %93, %88, %28
  %121 = load i64, ptr %8, align 8
  ret i64 %121
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !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 nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5queryPSt6vectorIlSaIlEES2_mmmmm(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, i64 noundef %6) local_unnamed_addr #0 {
  %8 = icmp ugt i64 %2, %5
  %9 = icmp ugt i64 %4, %5
  %10 = icmp ugt i64 %4, %3
  %11 = or i1 %9, %10
  %or.cond5567 = or i1 %11, %8
  br i1 %or.cond5567, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %12 = add i64 %5, 1
  %.not54 = icmp ult i64 %3, %5
  %invariant.umin = tail call i64 @llvm.umin.i64(i64 %5, i64 %3)
  br label %13

13:                                               ; preds = %.lr.ph, %tailrecurse
  %.tr6270 = phi i64 [ %6, %.lr.ph ], [ %50, %tailrecurse ]
  %.tr6069 = phi i64 [ %4, %.lr.ph ], [ %49, %tailrecurse ]
  %accumulator.tr68 = phi i64 [ 0, %.lr.ph ], [ %51, %tailrecurse ]
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.tr6270) #2
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %.not = icmp eq i64 %15, 0
  br i1 %.not, label %40, label %16

16:                                               ; preds = %13
  %17 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.tr6270) #2
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = sub i64 %12, %.tr6069
  %20 = mul i64 %18, %19
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.tr6270) #2
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = add i64 %22, %20
  store i64 %23, ptr %21, align 8, !tbaa !5
  %.not52 = icmp eq i64 %.tr6069, %5
  br i1 %.not52, label %38, label %24

24:                                               ; preds = %16
  %25 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.tr6270) #2
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = shl i64 %.tr6270, 1
  %28 = or disjoint i64 %27, 1
  %29 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %28) #2
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = add nsw i64 %30, %26
  store i64 %31, ptr %29, align 8, !tbaa !5
  %32 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.tr6270) #2
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = add i64 %27, 2
  %35 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %34) #2
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = add nsw i64 %36, %33
  store i64 %37, ptr %35, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %24, %16
  %39 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.tr6270) #2
  store i64 0, ptr %39, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %38, %13
  %.not53 = icmp ult i64 %.tr6069, %2
  %or.cond56 = or i1 %.not54, %.not53
  br i1 %or.cond56, label %tailrecurse, label %41

41:                                               ; preds = %40
  %42 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIlSaIlEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.tr6270) #2
  %43 = load i64, ptr %42, align 8, !tbaa !5
  br label %.loopexit

tailrecurse:                                      ; preds = %40
  %44 = add i64 %.tr6069, %5
  %45 = lshr i64 %44, 1
  %46 = shl i64 %.tr6270, 1
  %47 = or disjoint i64 %46, 1
  %48 = tail call noundef i64 @_Z5queryPSt6vectorIlSaIlEES2_mmmmm(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, i64 noundef %3, i64 noundef %.tr6069, i64 noundef %45, i64 noundef %47)
  %49 = add nuw i64 %45, 1
  %50 = add i64 %46, 2
  %51 = add nsw i64 %48, %accumulator.tr68
  %.not75 = icmp ult i64 %45, %invariant.umin
  br i1 %.not75, label %13, label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %7, %41
  %accumulator.tr65 = phi i64 [ %accumulator.tr68, %41 ], [ 0, %7 ], [ %51, %tailrecurse ]
  %.0 = phi i64 [ %43, %41 ], [ 0, %7 ], [ 0, %tailrecurse ]
  %accumulator.ret.tr = add nsw i64 %.0, %accumulator.tr65
  ret i64 %accumulator.ret.tr
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #1

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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