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

; 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
@lazy = external dso_local global [300300 x i32], align 16
@tmp = 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
define dso_local void @_Z13propagateLazyiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %90

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %37, %15
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 9
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %40

20:                                               ; preds = %16
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %22
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [9 x i32], ptr %23, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %28, %32
  %34 = srem i32 %33, 9
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %35) #2
  store i32 %27, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %20
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !5
  br label %16, !llvm.loop !9

40:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %56, %40
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = icmp slt i32 %42, 9
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %59

45:                                               ; preds = %41
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %47) #2
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %51
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [9 x i32], ptr %52, i64 0, i64 %54
  store i32 %49, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %45
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %8, align 4, !tbaa !5
  br label %41, !llvm.loop !11

59:                                               ; preds = %44
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = icmp ne i32 %60, %61
  br i1 %62, label %63, label %86

63:                                               ; preds = %59
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = mul nsw i32 2, %68
  %70 = add nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = add nsw i32 %73, %67
  store i32 %74, ptr %72, align 4, !tbaa !5
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = mul nsw i32 2, %79
  %81 = add nsw i32 %80, 2
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = add nsw i32 %84, %78
  store i32 %85, ptr %83, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %63, %59
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %88
  store i32 0, ptr %89, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %86, %14
  ret void
}

; 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

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 = { 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"}
!11 = distinct !{!11, !10}


; 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
@lazy = external dso_local local_unnamed_addr global [300300 x i32], align 16
@tmp = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z13propagateLazyiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %102, label %.preheader20.preheader

.preheader20.preheader:                           ; preds = %3
  %8 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %4, i64 0
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = srem i32 %6, 9
  %11 = sext i32 %10 to i64
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %11) #1
  store i32 %9, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %4, i64 1
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = srem i32 %16, 9
  %18 = sext i32 %17 to i64
  %19 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %18) #1
  store i32 %14, ptr %19, align 4, !tbaa !5
  %20 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %4, i64 2
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = add nsw i32 %22, 2
  %24 = srem i32 %23, 9
  %25 = sext i32 %24 to i64
  %26 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %25) #1
  store i32 %21, ptr %26, align 4, !tbaa !5
  %27 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %4, i64 3
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = add nsw i32 %29, 3
  %31 = srem i32 %30, 9
  %32 = sext i32 %31 to i64
  %33 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %32) #1
  store i32 %28, ptr %33, align 4, !tbaa !5
  %34 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %4, i64 4
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = add nsw i32 %36, 4
  %38 = srem i32 %37, 9
  %39 = sext i32 %38 to i64
  %40 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %39) #1
  store i32 %35, ptr %40, align 4, !tbaa !5
  %41 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %4, i64 5
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = add nsw i32 %43, 5
  %45 = srem i32 %44, 9
  %46 = sext i32 %45 to i64
  %47 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %46) #1
  store i32 %42, ptr %47, align 4, !tbaa !5
  %48 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %4, i64 6
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = add nsw i32 %50, 6
  %52 = srem i32 %51, 9
  %53 = sext i32 %52 to i64
  %54 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %53) #1
  store i32 %49, ptr %54, align 4, !tbaa !5
  %55 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %4, i64 7
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = add nsw i32 %57, 7
  %59 = srem i32 %58, 9
  %60 = sext i32 %59 to i64
  %61 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %60) #1
  store i32 %56, ptr %61, align 4, !tbaa !5
  %62 = getelementptr inbounds [300300 x [9 x i32]], ptr @tree, i64 0, i64 %4, i64 8
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = add nsw i32 %64, 8
  %66 = srem i32 %65, 9
  %67 = sext i32 %66 to i64
  %68 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef %67) #1
  store i32 %63, ptr %68, align 4, !tbaa !5
  %69 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef 0) #1
  %70 = load i32, ptr %69, align 4, !tbaa !5
  store i32 %70, ptr %8, align 4, !tbaa !5
  %71 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef 1) #1
  %72 = load i32, ptr %71, align 4, !tbaa !5
  store i32 %72, ptr %13, align 4, !tbaa !5
  %73 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef 2) #1
  %74 = load i32, ptr %73, align 4, !tbaa !5
  store i32 %74, ptr %20, align 4, !tbaa !5
  %75 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef 3) #1
  %76 = load i32, ptr %75, align 4, !tbaa !5
  store i32 %76, ptr %27, align 4, !tbaa !5
  %77 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef 4) #1
  %78 = load i32, ptr %77, align 4, !tbaa !5
  store i32 %78, ptr %34, align 4, !tbaa !5
  %79 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef 5) #1
  %80 = load i32, ptr %79, align 4, !tbaa !5
  store i32 %80, ptr %41, align 4, !tbaa !5
  %81 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef 6) #1
  %82 = load i32, ptr %81, align 4, !tbaa !5
  store i32 %82, ptr %48, align 4, !tbaa !5
  %83 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef 7) #1
  %84 = load i32, ptr %83, align 4, !tbaa !5
  store i32 %84, ptr %55, align 4, !tbaa !5
  %85 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tmp, i64 noundef 8) #1
  %86 = load i32, ptr %85, align 4, !tbaa !5
  store i32 %86, ptr %62, align 4, !tbaa !5
  %.not = icmp eq i32 %1, %2
  br i1 %.not, label %101, label %87

87:                                               ; preds = %.preheader20.preheader
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = shl nsw i32 %0, 1
  %90 = or disjoint i32 %89, 1
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !5
  %94 = add nsw i32 %93, %88
  store i32 %94, ptr %92, align 4, !tbaa !5
  %95 = load i32, ptr %5, align 4, !tbaa !5
  %96 = add nsw i32 %89, 2
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [300300 x i32], ptr @lazy, i64 0, i64 %97
  %99 = load i32, ptr %98, align 8, !tbaa !5
  %100 = add nsw i32 %99, %95
  store i32 %100, ptr %98, align 8, !tbaa !5
  br label %101

101:                                              ; preds = %87, %.preheader20.preheader
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %102

102:                                              ; preds = %3, %101
  ret void
}

; 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 #0 align 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 = { 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,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass