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

@.str = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @vmul(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %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
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1000, ptr %2, align 4, !tbaa !5
  %10 = call ptr @llvm.stacksave.p0()
  store ptr %10, ptr %3, align 8
  %11 = alloca i32, i64 1000, align 16
  %12 = alloca i32, i64 1000, align 16
  %13 = alloca i32, i64 1000000, align 16
  %14 = alloca i32, i64 1000000, align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 -1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %56, %0
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 1000
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %15
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %11, i64 %23
  store i32 %21, ptr %24, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %52, %19
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sub nsw i32 1000, %27
  %29 = icmp slt i32 %26, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %55

31:                                               ; preds = %25
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = add nsw i32 %32, 2
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %12, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %11, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %12, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = mul nsw i32 %40, %44
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = mul nsw i32 %46, 1000
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %14, i64 %50
  store i32 %45, ptr %51, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %31
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !5
  br label %25, !llvm.loop !9

55:                                               ; preds = %30
  br label %56

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

59:                                               ; preds = %18
  call void @vmul(ptr noundef %11, ptr noundef %12, ptr noundef %13, i32 noundef 1000)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %107, %59
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = icmp slt i32 %61, 1000
  br i1 %62, label %64, label %63

63:                                               ; preds = %60
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %110

64:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %103, %64
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = sub nsw i32 1000, %67
  %69 = icmp slt i32 %66, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %65
  store i32 11, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %106

71:                                               ; preds = %65
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = mul nsw i32 %72, 1000
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = add nsw i32 %73, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i32, ptr %14, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i32, ptr %11, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = load i32, ptr %9, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i32, ptr %12, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = mul nsw i32 %82, %86
  %88 = icmp ne i32 %78, %87
  br i1 %88, label %89, label %101

89:                                               ; preds = %71
  %90 = load i32, ptr %8, align 4, !tbaa !5
  %91 = load i32, ptr %8, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds i32, ptr %13, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = load i32, ptr %8, align 4, !tbaa !5
  %96 = load i32, ptr %8, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i32, ptr %14, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !5
  %100 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %90, i32 noundef %94, i32 noundef %95, i32 noundef %99)
  br label %101

101:                                              ; preds = %89, %71
  %102 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %102, ptr %4, align 4, !tbaa !5
  br label %103

103:                                              ; preds = %101
  %104 = load i32, ptr %9, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %9, align 4, !tbaa !5
  br label %65, !llvm.loop !12

106:                                              ; preds = %70
  br label %107

107:                                              ; preds = %106
  %108 = load i32, ptr %8, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %8, align 4, !tbaa !5
  br label %60, !llvm.loop !13

110:                                              ; preds = %63
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %111 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %111)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %112 = load i32, ptr %1, align 4
  ret i32 %112
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

@.str = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @vmul(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [1000 x i32], align 16
  %2 = alloca [1000 x i32], align 16
  %3 = alloca [1000000 x i32], align 16
  %4 = alloca [1000000 x i32], align 16
  br label %.lr.ph

.loopexit:                                        ; preds = %scalar.ph, %middle.block
  %indvars.iv.next40 = add nsw i64 %indvars.iv39, -1
  %exitcond46.not = icmp eq i64 %indvars.iv.next42, 1000
  br i1 %exitcond46.not, label %5, label %.lr.ph, !llvm.loop !5

5:                                                ; preds = %.loopexit
  call void @vmul(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef 1000)
  br label %.lr.ph34

.lr.ph:                                           ; preds = %.loopexit, %0
  %indvars.iv41 = phi i64 [ 0, %0 ], [ %indvars.iv.next42, %.loopexit ]
  %indvars.iv39 = phi i64 [ 1000, %0 ], [ %indvars.iv.next40, %.loopexit ]
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %6 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv41
  %7 = trunc nuw nsw i64 %indvars.iv.next42 to i32
  store i32 %7, ptr %6, align 4, !tbaa !7
  %.idx = mul i64 %indvars.iv41, 4000
  %invariant.gep = getelementptr i8, ptr %4, i64 %.idx
  %min.iters.check = icmp ult i64 %indvars.iv39, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %indvars.iv39, -4
  %broadcast.splatinsert = insertelement <4 x i64> poison, i64 %indvars.iv.next42, i64 0
  %broadcast.splat = shufflevector <4 x i64> %broadcast.splatinsert, <4 x i64> 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 ]
  %vec.ind = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %8 = add nuw nsw <4 x i64> %vec.ind, <i64 2, i64 2, i64 2, i64 2>
  %9 = getelementptr inbounds i32, ptr %2, i64 %index
  %10 = trunc <4 x i64> %8 to <4 x i32>
  store <4 x i32> %10, ptr %9, align 16, !tbaa !7
  %11 = mul nuw nsw <4 x i64> %8, %broadcast.splat
  %12 = getelementptr i32, ptr %invariant.gep, i64 %index
  %13 = trunc <4 x i64> %11 to <4 x i32>
  store <4 x i32> %13, ptr %12, align 16, !tbaa !7
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>
  %14 = icmp eq i64 %index.next, %n.vec
  br i1 %14, label %middle.block, label %vector.body, !llvm.loop !11

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

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

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %15 = add nuw nsw i64 %indvars.iv, 2
  %16 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %17 = trunc nuw nsw i64 %15 to i32
  store i32 %17, ptr %16, align 4, !tbaa !7
  %18 = mul nuw nsw i64 %15, %indvars.iv.next42
  %gep = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv
  %19 = trunc nuw nsw i64 %18 to i32
  store i32 %19, ptr %gep, align 4, !tbaa !7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv39
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !14

.lr.ph34:                                         ; preds = %._crit_edge, %5
  %indvars.iv55 = phi i64 [ 0, %5 ], [ %indvars.iv.next56, %._crit_edge ]
  %indvars.iv53 = phi i64 [ 1000, %5 ], [ %indvars.iv.next54, %._crit_edge ]
  %20 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv55
  %21 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv55
  %22 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv55
  %.idx61 = mul i64 %indvars.iv55, 4000
  %invariant.gep62 = getelementptr i8, ptr %4, i64 %.idx61
  %23 = trunc nuw nsw i64 %indvars.iv55 to i32
  br label %25

24:                                               ; preds = %._crit_edge
  ret i32 0

._crit_edge:                                      ; preds = %35
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %indvars.iv.next54 = add nsw i64 %indvars.iv53, -1
  %exitcond60.not = icmp eq i64 %indvars.iv.next56, 1000
  br i1 %exitcond60.not, label %24, label %.lr.ph34, !llvm.loop !15

25:                                               ; preds = %.lr.ph34, %35
  %indvars.iv47 = phi i64 [ 0, %.lr.ph34 ], [ %indvars.iv.next48, %35 ]
  %gep63 = getelementptr i32, ptr %invariant.gep62, i64 %indvars.iv47
  %26 = load i32, ptr %gep63, align 4, !tbaa !7
  %27 = load i32, ptr %20, align 4, !tbaa !7
  %28 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv47
  %29 = load i32, ptr %28, align 4, !tbaa !7
  %30 = mul nsw i32 %29, %27
  %.not = icmp eq i32 %26, %30
  br i1 %.not, label %35, label %31

31:                                               ; preds = %25
  %32 = load i32, ptr %21, align 4, !tbaa !7
  %33 = load i32, ptr %22, align 4, !tbaa !7
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %23, i32 noundef %32, i32 noundef %23, i32 noundef %33)
  br label %35

35:                                               ; preds = %31, %25
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next48, %indvars.iv53
  br i1 %exitcond52.not, label %._crit_edge, label %25, !llvm.loop !16
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { nofree nounwind "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = distinct !{!11, !6, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !6, !13, !12}
!15 = distinct !{!15, !6}
!16 = distinct !{!16, !6}


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