; LLVM IR from ROCm/aomp :: test/smoke/collapse-nonrectangle (collapse-nonrectangle)

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

12:                                               ; preds = %49, %4
  %13 = load i32, ptr %9, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %52

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

18:                                               ; preds = %45, %17
  %19 = load i32, ptr %11, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = sub nsw i32 %20, %21
  %23 = icmp slt i32 %19, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %48

25:                                               ; preds = %18
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %31, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = mul nsw i32 %30, %35
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = mul nsw i32 %38, %39
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = add nsw i32 %40, %41
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %37, i64 %43
  store i32 %36, ptr %44, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %25
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %11, align 4, !tbaa !9
  br label %18, !llvm.loop !11

48:                                               ; preds = %24
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %9, align 4, !tbaa !9
  br label %12, !llvm.loop !13

52:                                               ; preds = %16
  ret void
}

; 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

attributes #0 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @vmul(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %3, 0
  br i1 %5, label %.preheader.preheader, label %._crit_edge18

.preheader.preheader:                             ; preds = %4
  %6 = zext nneg i32 %3 to i64
  %7 = zext nneg i32 %3 to i64
  %8 = shl nuw nsw i64 %7, 2
  %9 = shl nuw nsw i64 %7, 2
  %scevgep28 = getelementptr i8, ptr %0, i64 %9
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv22 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next23, %._crit_edge ]
  %indvars.iv20 = phi i32 [ %3, %.preheader.preheader ], [ %indvars.iv.next21, %._crit_edge ]
  %10 = zext i32 %indvars.iv20 to i64
  %11 = zext i32 %indvars.iv20 to i64
  %12 = mul i64 %8, %indvars.iv22
  %scevgep = getelementptr i8, ptr %2, i64 %12
  %13 = zext i32 %indvars.iv20 to i64
  %14 = shl nuw nsw i64 %13, 2
  %scevgep27 = getelementptr i8, ptr %scevgep, i64 %14
  %scevgep29 = getelementptr i8, ptr %1, i64 %14
  %15 = icmp ult i64 %indvars.iv22, %6
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %16 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv22
  %17 = mul nuw nsw i64 %indvars.iv22, %7
  %wide.trip.count = zext i32 %indvars.iv20 to i64
  %invariant.gep = getelementptr inbounds i32, ptr %2, i64 %17
  %min.iters.check = icmp ult i32 %indvars.iv20, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %10, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %18 = load i32, ptr %16, align 4, !tbaa !5
  %19 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.prol
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = mul nsw i32 %20, %18
  %gep.prol = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv.prol
  store i32 %21, ptr %gep.prol, align 4, !tbaa !5
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !9

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %22 = sub nsw i64 %indvars.iv.ph, %10
  %23 = icmp ugt i64 %22, -4
  br i1 %23, label %._crit_edge, label %scalar.ph

vector.memcheck:                                  ; preds = %.lr.ph
  %bound0 = icmp ult ptr %scevgep, %scevgep28
  %bound1 = icmp ugt ptr %scevgep27, %0
  %found.conflict = and i1 %bound0, %bound1
  %bound030 = icmp ult ptr %scevgep, %scevgep29
  %bound131 = icmp ugt ptr %scevgep27, %1
  %found.conflict32 = and i1 %bound030, %bound131
  %conflict.rdx = or i1 %found.conflict, %found.conflict32
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %11, 4294967288
  %24 = load i32, ptr %16, align 4, !tbaa !5, !alias.scope !11
  %broadcast.splatinsert34 = insertelement <4 x i32> poison, i32 %24, i64 0
  %broadcast.splat35 = shufflevector <4 x i32> %broadcast.splatinsert34, <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 ]
  %25 = getelementptr inbounds i32, ptr %1, i64 %index
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %wide.load = load <4 x i32>, ptr %25, align 4, !tbaa !5, !alias.scope !14
  %wide.load33 = load <4 x i32>, ptr %26, align 4, !tbaa !5, !alias.scope !14
  %27 = mul nsw <4 x i32> %wide.load, %broadcast.splat35
  %28 = mul nsw <4 x i32> %wide.load33, %broadcast.splat35
  %29 = getelementptr inbounds i32, ptr %invariant.gep, i64 %index
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  store <4 x i32> %27, ptr %29, align 4, !tbaa !5, !alias.scope !16, !noalias !18
  store <4 x i32> %28, ptr %30, align 4, !tbaa !5, !alias.scope !16, !noalias !18
  %index.next = add nuw i64 %index, 8
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !19

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

._crit_edge18:                                    ; preds = %._crit_edge, %4
  ret void

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %.preheader
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %indvars.iv.next21 = add i32 %indvars.iv20, -1
  %exitcond26.not = icmp eq i64 %indvars.iv.next23, %7
  br i1 %exitcond26.not, label %._crit_edge18, label %.preheader, !llvm.loop !23

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %32 = load i32, ptr %16, align 4, !tbaa !5
  %33 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = mul nsw i32 %34, %32
  %gep = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv
  store i32 %35, ptr %gep, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %36 = load i32, ptr %16, align 4, !tbaa !5
  %37 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = mul nsw i32 %38, %36
  %gep.1 = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv.next
  store i32 %39, ptr %gep.1, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %40 = load i32, ptr %16, align 4, !tbaa !5
  %41 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.1
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = mul nsw i32 %42, %40
  %gep.2 = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv.next.1
  store i32 %43, ptr %gep.2, align 4, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %44 = load i32, ptr %16, align 4, !tbaa !5
  %45 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.2
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = mul nsw i32 %46, %44
  %gep.3 = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv.next.2
  store i32 %47, ptr %gep.3, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !24
}

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

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = !{!12}
!12 = distinct !{!12, !13}
!13 = distinct !{!13, !"LVerDomain"}
!14 = !{!15}
!15 = distinct !{!15, !13}
!16 = !{!17}
!17 = distinct !{!17, !13}
!18 = !{!12, !15}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20}
!24 = distinct !{!24, !20, !21}


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