; LLVM IR from brpapa/algorithms :: solutions/uri/2658.ll (Z10rangeQueryiiiii)

; 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<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@tree = external dso_local global [300300 x [9 x i32]], align 16
@ansQuery = 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 @_Z13propagateLazyiii(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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

16:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE6assignEmRKi(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 9, ptr noundef nonnull align 4 dereferenceable(4) %11)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %17

17:                                               ; preds = %16, %5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z13propagateLazyiii(i32 noundef %18, i32 noundef %19, i32 noundef %20)
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = icmp sgt i32 %21, %22
  br i1 %23, label %28, label %24

24:                                               ; preds = %17
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24, %17
  br label %80

29:                                               ; preds = %24
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = icmp sge i32 %30, %31
  br i1 %32, label %33, label %59

33:                                               ; preds = %29
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %37, label %59

37:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %55, %37
  %39 = load i32, ptr %12, align 4, !tbaa !5
  %40 = icmp slt i32 %39, 9
  br i1 %40, label %42, label %41

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

42:                                               ; preds = %38
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %44
  %46 = load i32, ptr %12, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [9 x i32], ptr %45, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef %51) #3
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %53, %49
  store i32 %54, ptr %52, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %42
  %56 = load i32, ptr %12, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %12, align 4, !tbaa !5
  br label %38, !llvm.loop !9

58:                                               ; preds = %41
  br label %80

59:                                               ; preds = %33, %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = add nsw i32 %60, %61
  %63 = sdiv i32 %62, 2
  store i32 %63, ptr %13, align 4, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = mul nsw i32 2, %64
  %66 = add nsw i32 %65, 1
  %67 = load i32, ptr %7, align 4, !tbaa !5
  %68 = load i32, ptr %13, align 4, !tbaa !5
  %69 = add nsw i32 %68, 0
  %70 = load i32, ptr %9, align 4, !tbaa !5
  %71 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z10rangeQueryiiiii(i32 noundef %66, i32 noundef %67, i32 noundef %69, i32 noundef %70, i32 noundef %71)
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = mul nsw i32 2, %72
  %74 = add nsw i32 %73, 2
  %75 = load i32, ptr %13, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z10rangeQueryiiiii(i32 noundef %74, i32 noundef %76, i32 noundef %77, i32 noundef %78, i32 noundef %79)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %80

80:                                               ; preds = %59, %58, %28
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE6assignEmRKi(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, ptr noundef nonnull align 4 dereferenceable(4)) #2 align 2

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@tree = external dso_local local_unnamed_addr global [300300 x [9 x i32]], align 16
@ansQuery = 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 @_Z13propagateLazyiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10rangeQueryiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca i32, align 4
  %7 = icmp eq i32 %0, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE6assignEmRKi(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 9, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  br label %9

9:                                                ; preds = %8, %5
  call void @_Z13propagateLazyiii(i32 noundef %0, i32 noundef %1, i32 noundef %2)
  %10 = icmp sgt i32 %1, %4
  %11 = icmp slt i32 %2, %3
  %or.cond = or i1 %11, %10
  br i1 %or.cond, label %.loopexit, label %12

12:                                               ; preds = %9
  %.not = icmp slt i32 %1, %3
  %.not33 = icmp sgt i32 %2, %4
  %or.cond34 = or i1 %.not, %.not33
  br i1 %or.cond34, label %59, label %.preheader

.preheader:                                       ; preds = %12
  %13 = sext i32 %0 to i64
  %14 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %13, i64 0
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 0) #3
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add nsw i32 %17, %15
  store i32 %18, ptr %16, align 4, !tbaa !5
  %19 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %13, i64 1
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 1) #3
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, %20
  store i32 %23, ptr %21, align 4, !tbaa !5
  %24 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %13, i64 2
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 2) #3
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %27, %25
  store i32 %28, ptr %26, align 4, !tbaa !5
  %29 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %13, i64 3
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 3) #3
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %32, %30
  store i32 %33, ptr %31, align 4, !tbaa !5
  %34 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %13, i64 4
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 4) #3
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %37, %35
  store i32 %38, ptr %36, align 4, !tbaa !5
  %39 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %13, i64 5
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 5) #3
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %42, %40
  store i32 %43, ptr %41, align 4, !tbaa !5
  %44 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %13, i64 6
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 6) #3
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = add nsw i32 %47, %45
  store i32 %48, ptr %46, align 4, !tbaa !5
  %49 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %13, i64 7
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 7) #3
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = add nsw i32 %52, %50
  store i32 %53, ptr %51, align 4, !tbaa !5
  %54 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %13, i64 8
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @ansQuery, i64 noundef 8) #3
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = add nsw i32 %57, %55
  store i32 %58, ptr %56, align 4, !tbaa !5
  br label %.loopexit

59:                                               ; preds = %12
  %60 = add nsw i32 %2, %1
  %61 = sdiv i32 %60, 2
  %62 = shl nsw i32 %0, 1
  %63 = or disjoint i32 %62, 1
  call void @_Z10rangeQueryiiiii(i32 noundef %63, i32 noundef %1, i32 noundef %61, i32 noundef %3, i32 noundef %4)
  %64 = add nsw i32 %62, 2
  %65 = add nsw i32 %61, 1
  call void @_Z10rangeQueryiiiii(i32 noundef %64, i32 noundef %65, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %9, %59
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE6assignEmRKi(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2 align 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass