; LLVM IR from ROCm/aomp :: test/smoke-dev/zero-copy-xnack-enable-dgpu-map-disable-apu (zero_copy)

; 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 [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef 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 ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 1024, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %12, i64 4)
  %14 = extractvalue { i64, i1 } %13, 1
  %15 = extractvalue { i64, i1 } %13, 0
  %16 = select i1 %14, i64 -1, i64 %15
  %17 = call noalias noundef nonnull ptr @_Znam(i64 noundef %16) #7
  store ptr %17, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 3, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = zext i32 %18 to i64
  %20 = call ptr @llvm.stacksave.p0()
  store ptr %20, ptr %5, align 8
  %21 = alloca i32, i64 %19, align 16
  store i64 %19, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %32, %0
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %35

27:                                               ; preds = %22
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %21, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %27
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %7, align 4, !tbaa !5
  br label %22, !llvm.loop !11

35:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %54, %35
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %57

41:                                               ; preds = %36
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %21, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = add nsw i32 %42, %46
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = load ptr, ptr %3, align 8, !tbaa !9
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %50, i64 %52
  store i32 %49, ptr %53, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %41
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %8, align 4, !tbaa !5
  br label %36, !llvm.loop !13

57:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %82, %57
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %85

63:                                               ; preds = %58
  %64 = load ptr, ptr %3, align 8, !tbaa !9
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %64, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = load i32, ptr %10, align 4, !tbaa !5
  %70 = load i32, ptr %10, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %21, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = add nsw i32 %69, %73
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = add nsw i32 %74, %75
  %77 = icmp ne i32 %68, %76
  br i1 %77, label %78, label %81

78:                                               ; preds = %63
  %79 = load i32, ptr %9, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %9, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %78, %63
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %10, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %10, align 4, !tbaa !5
  br label %58, !llvm.loop !14

85:                                               ; preds = %62
  %86 = load i32, ptr %9, align 4, !tbaa !5
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %88, label %90

88:                                               ; preds = %85
  %89 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %90

90:                                               ; preds = %88, %85
  %91 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %91, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  %92 = load ptr, ptr %5, align 8
  call void @llvm.stackrestore.p0(ptr %92)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  %93 = load i32, ptr %1, align 4
  ret i32 %93
}

; 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 speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

attributes #0 = { mustprogress norecurse 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 speculatable willreturn memory(none) }
attributes #3 = { nobuiltin allocsize(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 #4 = { nocallback nofree nosync nounwind willreturn }
attributes #5 = { "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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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"

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
vector.ph:
  %0 = tail call noalias noundef nonnull dereferenceable(4096) ptr @_Znam(i64 noundef 4096) #4
  %1 = alloca [1024 x i32], align 16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.3, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next.3, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %2 = getelementptr inbounds i32, ptr %1, i64 %index
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  store <4 x i32> %vec.ind, ptr %2, align 16, !tbaa !5
  store <4 x i32> %step.add, ptr %3, align 16, !tbaa !5
  %index.next = or disjoint i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %step.add.1 = add <4 x i32> %vec.ind, <i32 12, i32 12, i32 12, i32 12>
  %4 = getelementptr inbounds i32, ptr %1, i64 %index.next
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store <4 x i32> %vec.ind.next, ptr %4, align 16, !tbaa !5
  store <4 x i32> %step.add.1, ptr %5, align 16, !tbaa !5
  %index.next.1 = or disjoint i64 %index, 16
  %vec.ind.next.1 = add <4 x i32> %vec.ind, <i32 16, i32 16, i32 16, i32 16>
  %step.add.2 = add <4 x i32> %vec.ind, <i32 20, i32 20, i32 20, i32 20>
  %6 = getelementptr inbounds i32, ptr %1, i64 %index.next.1
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  store <4 x i32> %vec.ind.next.1, ptr %6, align 16, !tbaa !5
  store <4 x i32> %step.add.2, ptr %7, align 16, !tbaa !5
  %index.next.2 = or disjoint i64 %index, 24
  %vec.ind.next.2 = add <4 x i32> %vec.ind, <i32 24, i32 24, i32 24, i32 24>
  %step.add.3 = add <4 x i32> %vec.ind, <i32 28, i32 28, i32 28, i32 28>
  %8 = getelementptr inbounds i32, ptr %1, i64 %index.next.2
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  store <4 x i32> %vec.ind.next.2, ptr %8, align 16, !tbaa !5
  store <4 x i32> %step.add.3, ptr %9, align 16, !tbaa !5
  %index.next.3 = add nuw nsw i64 %index, 32
  %vec.ind.next.3 = add <4 x i32> %vec.ind, <i32 32, i32 32, i32 32, i32 32>
  %10 = icmp eq i64 %index.next.3, 1024
  br i1 %10, label %vector.body49, label %vector.body, !llvm.loop !9

vector.body49:                                    ; preds = %vector.body, %vector.body49
  %index50 = phi i64 [ %index.next56.1, %vector.body49 ], [ 0, %vector.body ]
  %vec.ind51 = phi <4 x i32> [ %vec.ind.next54.1, %vector.body49 ], [ <i32 0, i32 1, i32 2, i32 3>, %vector.body ]
  %11 = getelementptr inbounds i32, ptr %1, i64 %index50
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <4 x i32>, ptr %11, align 16, !tbaa !5
  %wide.load55 = load <4 x i32>, ptr %12, align 16, !tbaa !5
  %13 = add <4 x i32> %vec.ind51, <i32 3, i32 3, i32 3, i32 3>
  %14 = add <4 x i32> %vec.ind51, <i32 7, i32 7, i32 7, i32 7>
  %15 = add <4 x i32> %13, %wide.load
  %16 = add <4 x i32> %14, %wide.load55
  %17 = getelementptr inbounds i32, ptr %0, i64 %index50
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  store <4 x i32> %15, ptr %17, align 4, !tbaa !5
  store <4 x i32> %16, ptr %18, align 4, !tbaa !5
  %index.next56 = or disjoint i64 %index50, 8
  %19 = getelementptr inbounds i32, ptr %1, i64 %index.next56
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  %wide.load.1 = load <4 x i32>, ptr %19, align 16, !tbaa !5
  %wide.load55.1 = load <4 x i32>, ptr %20, align 16, !tbaa !5
  %21 = add <4 x i32> %vec.ind51, <i32 11, i32 11, i32 11, i32 11>
  %22 = add <4 x i32> %vec.ind51, <i32 15, i32 15, i32 15, i32 15>
  %23 = add <4 x i32> %21, %wide.load.1
  %24 = add <4 x i32> %22, %wide.load55.1
  %25 = getelementptr inbounds i32, ptr %0, i64 %index.next56
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  store <4 x i32> %23, ptr %25, align 4, !tbaa !5
  store <4 x i32> %24, ptr %26, align 4, !tbaa !5
  %index.next56.1 = add nuw nsw i64 %index50, 16
  %vec.ind.next54.1 = add <4 x i32> %vec.ind51, <i32 16, i32 16, i32 16, i32 16>
  %27 = icmp eq i64 %index.next56.1, 1024
  br i1 %27, label %vector.body61, label %vector.body49, !llvm.loop !13

vector.body61:                                    ; preds = %vector.body49, %vector.body61
  %index62 = phi i64 [ %index.next72, %vector.body61 ], [ 0, %vector.body49 ]
  %vec.phi = phi <4 x i32> [ %40, %vector.body61 ], [ zeroinitializer, %vector.body49 ]
  %vec.phi63 = phi <4 x i32> [ %41, %vector.body61 ], [ zeroinitializer, %vector.body49 ]
  %vec.ind64 = phi <4 x i32> [ %vec.ind.next67, %vector.body61 ], [ <i32 0, i32 1, i32 2, i32 3>, %vector.body49 ]
  %28 = getelementptr inbounds i32, ptr %0, i64 %index62
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %wide.load68 = load <4 x i32>, ptr %28, align 4, !tbaa !5
  %wide.load69 = load <4 x i32>, ptr %29, align 4, !tbaa !5
  %30 = getelementptr inbounds i32, ptr %1, i64 %index62
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  %wide.load70 = load <4 x i32>, ptr %30, align 16, !tbaa !5
  %wide.load71 = load <4 x i32>, ptr %31, align 16, !tbaa !5
  %32 = add nuw nsw <4 x i32> %vec.ind64, <i32 3, i32 3, i32 3, i32 3>
  %33 = add <4 x i32> %vec.ind64, <i32 7, i32 7, i32 7, i32 7>
  %34 = add <4 x i32> %32, %wide.load70
  %35 = add <4 x i32> %33, %wide.load71
  %36 = icmp ne <4 x i32> %wide.load68, %34
  %37 = icmp ne <4 x i32> %wide.load69, %35
  %38 = zext <4 x i1> %36 to <4 x i32>
  %39 = zext <4 x i1> %37 to <4 x i32>
  %40 = add <4 x i32> %vec.phi, %38
  %41 = add <4 x i32> %vec.phi63, %39
  %index.next72 = add nuw i64 %index62, 8
  %vec.ind.next67 = add <4 x i32> %vec.ind64, <i32 8, i32 8, i32 8, i32 8>
  %42 = icmp eq i64 %index.next72, 1024
  br i1 %42, label %middle.block57, label %vector.body61, !llvm.loop !14

middle.block57:                                   ; preds = %vector.body61
  %bin.rdx = add <4 x i32> %41, %40
  %43 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %middle.block57
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %47

47:                                               ; preds = %45, %middle.block57
  ret i32 %43
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #3

attributes #0 = { mustprogress norecurse 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 = { nobuiltin allocsize(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 = { 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" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { builtin allocsize(0) }

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


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