; LLVM IR from ROCm/aomp :: test/omp5/loop (loop)

; 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
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 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
  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
  %9 = call ptr @llvm.stacksave.p0()
  store ptr %9, ptr %3, align 8
  %10 = alloca i32, i64 1000, align 16
  %11 = alloca i32, i64 1000, align 16
  %12 = alloca i32, i64 1000000, align 16
  %13 = 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 %14

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

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

18:                                               ; preds = %14
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %10, i64 %22
  store i32 %20, ptr %23, 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 %24

24:                                               ; preds = %49, %18
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = icmp slt i32 %25, 1000
  br i1 %26, label %28, label %27

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

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

49:                                               ; preds = %28
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !5
  br label %24, !llvm.loop !9

52:                                               ; preds = %27
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !5
  br label %14, !llvm.loop !11

56:                                               ; preds = %17
  call void @vmul(ptr noundef %10, ptr noundef %11, ptr noundef %12, 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 %57

57:                                               ; preds = %89, %56
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = icmp slt i32 %58, 1000000
  br i1 %59, label %61, label %60

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

61:                                               ; preds = %57
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %12, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %13, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = icmp ne i32 %65, %69
  br i1 %70, label %71, label %88

71:                                               ; preds = %61
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = icmp eq i32 %72, -1
  br i1 %73, label %74, label %86

74:                                               ; preds = %71
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %12, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = load i32, ptr %8, align 4, !tbaa !5
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i32, ptr %13, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %75, i32 noundef %79, i32 noundef %80, i32 noundef %84)
  br label %86

86:                                               ; preds = %74, %71
  %87 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %87, ptr %4, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %86, %61
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %8, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %8, align 4, !tbaa !5
  br label %57, !llvm.loop !12

92:                                               ; preds = %60
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = icmp eq i32 %93, -1
  br i1 %94, label %95, label %97

95:                                               ; preds = %92
  %96 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %110

97:                                               ; preds = %92
  %98 = load i32, ptr %4, align 4, !tbaa !5
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i32, ptr %12, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = load i32, ptr %4, align 4, !tbaa !5
  %104 = load i32, ptr %4, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds i32, ptr %13, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !5
  %108 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %98, i32 noundef %102, i32 noundef %103, i32 noundef %107)
  %109 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 1, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %110

110:                                              ; preds = %97, %95
  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}


; 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
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 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 range(i32 0, 2) 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 %vector.ph

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

vector.ph:                                        ; preds = %0, %middle.block
  %indvars.iv39 = phi i64 [ 0, %0 ], [ %indvars.iv.next40, %middle.block ]
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %6 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv39
  %7 = trunc nuw nsw i64 %indvars.iv.next40 to i32
  store i32 %7, ptr %6, align 4, !tbaa !5
  %.idx = mul i64 %indvars.iv39, 4000
  %invariant.gep = getelementptr i8, ptr %4, i64 %.idx
  %broadcast.splatinsert = insertelement <4 x i64> poison, i64 %indvars.iv.next40, 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 !5
  %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 !5
  %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, 1000
  br i1 %14, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %exitcond42.not = icmp eq i64 %indvars.iv.next40, 1000
  br i1 %exitcond42.not, label %5, label %vector.ph, !llvm.loop !13

15:                                               ; preds = %27
  %16 = icmp eq i32 %.1, -1
  br i1 %16, label %35, label %28

17:                                               ; preds = %5, %27
  %indvars.iv43 = phi i64 [ 0, %5 ], [ %indvars.iv.next44, %27 ]
  %.03036 = phi i32 [ -1, %5 ], [ %.1, %27 ]
  %18 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv43
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv43
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not = icmp eq i32 %19, %21
  br i1 %.not, label %27, label %22

22:                                               ; preds = %17
  %23 = icmp eq i32 %.03036, -1
  %24 = trunc nuw nsw i64 %indvars.iv43 to i32
  br i1 %23, label %25, label %27

25:                                               ; preds = %22
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %24, i32 noundef %19, i32 noundef %24, i32 noundef %21)
  br label %27

27:                                               ; preds = %22, %25, %17
  %.1 = phi i32 [ %.03036, %17 ], [ %24, %25 ], [ %24, %22 ]
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next44, 1000000
  br i1 %exitcond46.not, label %15, label %17, !llvm.loop !14

28:                                               ; preds = %15
  %29 = sext i32 %.1 to i64
  %30 = getelementptr inbounds i32, ptr %3, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = getelementptr inbounds i32, ptr %4, i64 %29
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.1, i32 noundef %31, i32 noundef %.1, i32 noundef %33)
  br label %35

35:                                               ; preds = %15, %28
  %.str.3.sink = phi ptr [ @.str.3, %28 ], [ @.str.1, %15 ]
  %.031 = phi i32 [ 1, %28 ], [ 0, %15 ]
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.3.sink)
  ret i32 %.031
}

; 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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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