; LLVM IR from ROCm/aomp :: test/LLNL/openmp5.0-tests/test_noncontiguous_update.ll (Z10bc_offloadPiii)

; 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 nounwind uwtable
define dso_local void @_Z10bc_offloadPiii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %40, %3
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = add nsw i32 %14, 1
  %16 = icmp sle i32 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %45

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

19:                                               ; preds = %36, %18
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = add nsw i32 %21, 2
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %39

25:                                               ; preds = %19
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = add nsw i32 %29, 2
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = mul nsw i32 %30, %31
  %33 = add nsw i32 %28, %32
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %27, i64 %34
  store i32 %26, ptr %35, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %25
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %9, align 4, !tbaa !9
  br label %19, !llvm.loop !11

39:                                               ; preds = %24
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %7, align 4, !tbaa !9
  br label %12, !llvm.loop !13

45:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %74, %45
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = icmp sle i32 %47, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %46
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %79

52:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %70, %52
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = add nsw i32 %55, 2
  %57 = icmp slt i32 %54, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %53
  store i32 11, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %73

59:                                               ; preds = %53
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !9
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = add nsw i32 %63, 2
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = mul nsw i32 %64, %65
  %67 = add nsw i32 %62, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %61, i64 %68
  store i32 %60, ptr %69, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %59
  %71 = load i32, ptr %11, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %11, align 4, !tbaa !9
  br label %53, !llvm.loop !14

73:                                               ; preds = %58
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = add nsw i32 %77, %76
  store i32 %78, ptr %10, align 4, !tbaa !9
  br label %46, !llvm.loop !15

79:                                               ; preds = %51
  ret void
}

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


; 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 nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local void @_Z10bc_offloadPiii(ptr nocapture noundef writeonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = add i32 %1, 1
  %.not33 = icmp slt i32 %1, -1
  br i1 %.not33, label %._crit_edge38, label %.preheader31.us.preheader

.preheader31.us.preheader:                        ; preds = %3
  %5 = add i32 %1, 2
  %6 = sext i32 %5 to i64
  %smax = tail call i32 @llvm.smax.i32(i32 %5, i32 1)
  %7 = sext i32 %4 to i64
  %wide.trip.count = zext nneg i32 %smax to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %8 = icmp slt i32 %5, 4
  br i1 %8, label %._crit_edge.us.unr-lcssa, label %.preheader31.us.preheader.new

.preheader31.us.preheader.new:                    ; preds = %.preheader31.us.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %9

9:                                                ; preds = %9, %.preheader31.us.preheader.new
  %indvars.iv = phi i64 [ 0, %.preheader31.us.preheader.new ], [ %indvars.iv.next.3, %9 ]
  %niter = phi i64 [ 0, %.preheader31.us.preheader.new ], [ %niter.next.3, %9 ]
  %10 = mul nuw nsw i64 %indvars.iv, %6
  %11 = getelementptr inbounds i32, ptr %0, i64 %10
  store i32 %2, ptr %11, align 4, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %12 = mul nuw nsw i64 %indvars.iv.next, %6
  %13 = getelementptr inbounds i32, ptr %0, i64 %12
  store i32 %2, ptr %13, align 4, !tbaa !5
  %indvars.iv.next.171 = or disjoint i64 %indvars.iv, 2
  %14 = mul nuw nsw i64 %indvars.iv.next.171, %6
  %15 = getelementptr inbounds i32, ptr %0, i64 %14
  store i32 %2, ptr %15, align 4, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %16 = mul nuw nsw i64 %indvars.iv.next.2, %6
  %17 = getelementptr inbounds i32, ptr %0, i64 %16
  store i32 %2, ptr %17, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %9, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %9, %.preheader31.us.preheader
  %indvars.iv.unr = phi i64 [ 0, %.preheader31.us.preheader ], [ %indvars.iv.next.3, %9 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %18 = mul nsw i64 %indvars.iv.epil, %6
  %19 = getelementptr inbounds i32, ptr %0, i64 %18
  store i32 %2, ptr %19, align 4, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !11

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %invariant.gep = getelementptr i32, ptr %0, i64 %7
  %xtraiter73 = and i64 %wide.trip.count, 3
  %20 = icmp slt i32 %5, 4
  br i1 %20, label %.preheader30.unr-lcssa, label %._crit_edge.us.new

._crit_edge.us.new:                               ; preds = %._crit_edge.us
  %unroll_iter76 = and i64 %wide.trip.count, 2147483644
  br label %21

21:                                               ; preds = %21, %._crit_edge.us.new
  %indvars.iv.1 = phi i64 [ 0, %._crit_edge.us.new ], [ %indvars.iv.next.1.3, %21 ]
  %niter77 = phi i64 [ 0, %._crit_edge.us.new ], [ %niter77.next.3, %21 ]
  %22 = mul nuw nsw i64 %indvars.iv.1, %6
  %gep = getelementptr i32, ptr %invariant.gep, i64 %22
  store i32 %2, ptr %gep, align 4, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv.1, 1
  %23 = mul nuw nsw i64 %indvars.iv.next.1, %6
  %gep.1 = getelementptr i32, ptr %invariant.gep, i64 %23
  store i32 %2, ptr %gep.1, align 4, !tbaa !5
  %indvars.iv.next.1.1 = or disjoint i64 %indvars.iv.1, 2
  %24 = mul nuw nsw i64 %indvars.iv.next.1.1, %6
  %gep.2 = getelementptr i32, ptr %invariant.gep, i64 %24
  store i32 %2, ptr %gep.2, align 4, !tbaa !5
  %indvars.iv.next.1.2 = or disjoint i64 %indvars.iv.1, 3
  %25 = mul nuw nsw i64 %indvars.iv.next.1.2, %6
  %gep.3 = getelementptr i32, ptr %invariant.gep, i64 %25
  store i32 %2, ptr %gep.3, align 4, !tbaa !5
  %indvars.iv.next.1.3 = add nuw nsw i64 %indvars.iv.1, 4
  %niter77.next.3 = add i64 %niter77, 4
  %niter77.ncmp.3 = icmp eq i64 %niter77.next.3, %unroll_iter76
  br i1 %niter77.ncmp.3, label %.preheader30.unr-lcssa, label %21, !llvm.loop !9

.preheader30.unr-lcssa:                           ; preds = %21, %._crit_edge.us
  %indvars.iv.1.unr = phi i64 [ 0, %._crit_edge.us ], [ %indvars.iv.next.1.3, %21 ]
  %lcmp.mod75.not = icmp eq i64 %xtraiter73, 0
  br i1 %lcmp.mod75.not, label %.preheader30, label %.epil.preheader72

.epil.preheader72:                                ; preds = %.preheader30.unr-lcssa, %.epil.preheader72
  %indvars.iv.1.epil = phi i64 [ %indvars.iv.next.1.epil, %.epil.preheader72 ], [ %indvars.iv.1.unr, %.preheader30.unr-lcssa ]
  %epil.iter74 = phi i64 [ %epil.iter74.next, %.epil.preheader72 ], [ 0, %.preheader30.unr-lcssa ]
  %26 = mul nsw i64 %indvars.iv.1.epil, %6
  %gep.epil = getelementptr i32, ptr %invariant.gep, i64 %26
  store i32 %2, ptr %gep.epil, align 4, !tbaa !5
  %indvars.iv.next.1.epil = add nuw nsw i64 %indvars.iv.1.epil, 1
  %epil.iter74.next = add i64 %epil.iter74, 1
  %epil.iter74.cmp.not = icmp eq i64 %epil.iter74.next, %xtraiter73
  br i1 %epil.iter74.cmp.not, label %.preheader30, label %.epil.preheader72, !llvm.loop !13

.preheader30:                                     ; preds = %.epil.preheader72, %.preheader30.unr-lcssa
  br i1 %.not33, label %._crit_edge38, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader30
  %27 = add i32 %1, 2
  %smax49 = tail call i32 @llvm.smax.i32(i32 %27, i32 1)
  %28 = sext i32 %4 to i64
  %29 = sext i32 %27 to i64
  %wide.trip.count50 = zext nneg i32 %smax49 to i64
  %min.iters.check = icmp slt i32 %5, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.preheader.us.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %2, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %30 = getelementptr inbounds i32, ptr %0, i64 %index
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  store <4 x i32> %broadcast.splat, ptr %30, align 4, !tbaa !5
  store <4 x i32> %broadcast.splat, ptr %31, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge.us39, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us.preheader
  %indvars.iv46.ph = phi i64 [ 0, %.preheader.us.preheader ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %scalar.ph ], [ %indvars.iv46.ph, %scalar.ph.preheader ]
  %33 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv46
  store i32 %2, ptr %33, align 4, !tbaa !5
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond51.not = icmp eq i64 %indvars.iv.next47, %wide.trip.count50
  br i1 %exitcond51.not, label %._crit_edge.us39, label %scalar.ph, !llvm.loop !17

._crit_edge.us39:                                 ; preds = %scalar.ph, %middle.block
  %34 = mul nsw i64 %28, %29
  %invariant.gep55 = getelementptr i32, ptr %0, i64 %34
  %min.iters.check59 = icmp slt i32 %5, 8
  br i1 %min.iters.check59, label %scalar.ph58.preheader, label %vector.ph60

vector.ph60:                                      ; preds = %._crit_edge.us39
  %n.vec62 = and i64 %wide.trip.count, 2147483640
  %broadcast.splatinsert66 = insertelement <4 x i32> poison, i32 %2, i64 0
  %broadcast.splat67 = shufflevector <4 x i32> %broadcast.splatinsert66, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body64

vector.body64:                                    ; preds = %vector.body64, %vector.ph60
  %index65 = phi i64 [ 0, %vector.ph60 ], [ %index.next68, %vector.body64 ]
  %35 = getelementptr i32, ptr %invariant.gep55, i64 %index65
  %36 = getelementptr i8, ptr %35, i64 16
  store <4 x i32> %broadcast.splat67, ptr %35, align 4, !tbaa !5
  store <4 x i32> %broadcast.splat67, ptr %36, align 4, !tbaa !5
  %index.next68 = add nuw i64 %index65, 8
  %37 = icmp eq i64 %index.next68, %n.vec62
  br i1 %37, label %middle.block57, label %vector.body64, !llvm.loop !18

middle.block57:                                   ; preds = %vector.body64
  %cmp.n69 = icmp eq i64 %n.vec62, %wide.trip.count
  br i1 %cmp.n69, label %._crit_edge38, label %scalar.ph58.preheader

scalar.ph58.preheader:                            ; preds = %middle.block57, %._crit_edge.us39
  %indvars.iv46.1.ph = phi i64 [ 0, %._crit_edge.us39 ], [ %n.vec62, %middle.block57 ]
  br label %scalar.ph58

scalar.ph58:                                      ; preds = %scalar.ph58.preheader, %scalar.ph58
  %indvars.iv46.1 = phi i64 [ %indvars.iv.next47.1, %scalar.ph58 ], [ %indvars.iv46.1.ph, %scalar.ph58.preheader ]
  %gep56 = getelementptr i32, ptr %invariant.gep55, i64 %indvars.iv46.1
  store i32 %2, ptr %gep56, align 4, !tbaa !5
  %indvars.iv.next47.1 = add nuw nsw i64 %indvars.iv46.1, 1
  %exitcond51.1.not = icmp eq i64 %indvars.iv.next47.1, %wide.trip.count50
  br i1 %exitcond51.1.not, label %._crit_edge38, label %scalar.ph58, !llvm.loop !19

._crit_edge38:                                    ; preds = %scalar.ph58, %middle.block57, %3, %.preheader30
  ret void
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: write) 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) }

!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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !10, !15, !16}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !10, !16, !15}
!18 = distinct !{!18, !10, !15, !16}
!19 = distinct !{!19, !10, !16, !15}


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