; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C++/Data-Structures/Tree/Segment_Tree_with_Lazy_Propagation.ll (Z5queryxxxxx)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@tree = external dso_local global %"class.std::vector", align 8

; 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 nounwind uwtable
declare dso_local void @_Z4pushx(i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 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

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

18:                                               ; preds = %5
  store i64 -9223372036854775807, ptr %6, align 8
  br label %64

19:                                               ; preds = %5
  %20 = load i64, ptr %7, align 8, !tbaa !5
  call void @_Z4pushx(i64 noundef %20)
  %21 = load i64, ptr %10, align 8, !tbaa !5
  %22 = load i64, ptr %9, align 8, !tbaa !5
  %23 = icmp sgt i64 %21, %22
  br i1 %23, label %28, label %24

24:                                               ; preds = %19
  %25 = load i64, ptr %11, align 8, !tbaa !5
  %26 = load i64, ptr %8, align 8, !tbaa !5
  %27 = icmp slt i64 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24, %19
  store i64 -9223372036854775807, ptr %6, align 8
  br label %64

29:                                               ; preds = %24
  %30 = load i64, ptr %8, align 8, !tbaa !5
  %31 = load i64, ptr %10, align 8, !tbaa !5
  %32 = icmp sge i64 %30, %31
  br i1 %32, label %33, label %41

33:                                               ; preds = %29
  %34 = load i64, ptr %9, align 8, !tbaa !5
  %35 = load i64, ptr %11, align 8, !tbaa !5
  %36 = icmp sle i64 %34, %35
  br i1 %36, label %37, label %41

37:                                               ; preds = %33
  %38 = load i64, ptr %7, align 8, !tbaa !5
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %38) #4
  %40 = load i64, ptr %39, align 8, !tbaa !5
  store i64 %40, ptr %6, align 8
  br label %64

41:                                               ; preds = %33, %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %42 = load i64, ptr %8, align 8, !tbaa !5
  %43 = load i64, ptr %9, align 8, !tbaa !5
  %44 = add nsw i64 %42, %43
  %45 = sdiv i64 %44, 2
  store i64 %45, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %46 = load i64, ptr %7, align 8, !tbaa !5
  %47 = mul nsw i64 %46, 2
  %48 = load i64, ptr %8, align 8, !tbaa !5
  %49 = load i64, ptr %12, align 8, !tbaa !5
  %50 = load i64, ptr %10, align 8, !tbaa !5
  %51 = load i64, ptr %11, align 8, !tbaa !5
  %52 = call noundef i64 @_Z5queryxxxxx(i64 noundef %47, i64 noundef %48, i64 noundef %49, i64 noundef %50, i64 noundef %51)
  store i64 %52, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %53 = load i64, ptr %7, align 8, !tbaa !5
  %54 = mul nsw i64 %53, 2
  %55 = add nsw i64 %54, 1
  %56 = load i64, ptr %12, align 8, !tbaa !5
  %57 = add nsw i64 %56, 1
  %58 = load i64, ptr %9, align 8, !tbaa !5
  %59 = load i64, ptr %10, align 8, !tbaa !5
  %60 = load i64, ptr %11, align 8, !tbaa !5
  %61 = call noundef i64 @_Z5queryxxxxx(i64 noundef %55, i64 noundef %57, i64 noundef %58, i64 noundef %59, i64 noundef %60)
  store i64 %61, ptr %14, align 8, !tbaa !5
  %62 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef nonnull align 8 dereferenceable(8) %14)
  %63 = load i64, ptr %62, align 8, !tbaa !5
  store i64 %63, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %64

64:                                               ; preds = %41, %37, %28, %18
  %65 = load i64, ptr %6, align 8
  ret i64 %65
}

attributes #0 = { 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 = { 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 #4 = { 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"}


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@tree = external dso_local global %"class.std::vector", align 8

; 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
declare dso_local void @_Z4pushx(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5queryxxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #1 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = icmp sgt i64 %3, %4
  br i1 %8, label %common.ret31, label %9

9:                                                ; preds = %5
  tail call void @_Z4pushx(i64 noundef %0)
  %10 = icmp sgt i64 %3, %2
  %11 = icmp slt i64 %4, %1
  %or.cond = or i1 %10, %11
  br i1 %or.cond, label %common.ret31, label %12

12:                                               ; preds = %9
  %.not = icmp slt i64 %1, %3
  %.not29 = icmp sgt i64 %2, %4
  %or.cond30 = or i1 %.not, %.not29
  br i1 %or.cond30, label %16, label %13

13:                                               ; preds = %12
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %0) #3
  %15 = load i64, ptr %14, align 8, !tbaa !5
  br label %common.ret31

common.ret31:                                     ; preds = %9, %5, %13, %16
  %common.ret31.op = phi i64 [ %25, %16 ], [ %15, %13 ], [ -9223372036854775807, %5 ], [ -9223372036854775807, %9 ]
  ret i64 %common.ret31.op

16:                                               ; preds = %12
  %17 = add nsw i64 %2, %1
  %18 = sdiv i64 %17, 2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %19 = shl nsw i64 %0, 1
  %20 = tail call noundef i64 @_Z5queryxxxxx(i64 noundef %19, i64 noundef %1, i64 noundef %18, i64 noundef %3, i64 noundef %4)
  store i64 %20, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  %21 = or disjoint i64 %19, 1
  %22 = add nsw i64 %18, 1
  %23 = tail call noundef i64 @_Z5queryxxxxx(i64 noundef %21, i64 noundef %22, i64 noundef %2, i64 noundef %3, i64 noundef %4)
  store i64 %23, ptr %7, align 8, !tbaa !5
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %25 = load i64, ptr %24, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  br label %common.ret31
}

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,TailCallElimPass