; LLVM IR from ROCm/aomp :: test/smoke/min_reduction (min_reduction)

; 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 [37 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 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 i64, align 8
  %5 = alloca double, align 8
  %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 100000, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = call ptr @llvm.stacksave.p0()
  store ptr %11, ptr %3, align 8
  %12 = alloca double, i64 %10, align 16
  store i64 %10, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sitofp i32 %13 to double
  store double %14, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %15

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

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %30

20:                                               ; preds = %15
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sitofp i32 %21 to double
  %23 = fadd double %22, 1.000000e+00
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %12, i64 %25
  store double %23, ptr %26, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %20
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %6, align 4, !tbaa !5
  br label %15, !llvm.loop !11

30:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %52, %30
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %31
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %12, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = load double, ptr %5, align 8, !tbaa !9
  %42 = fcmp olt double %40, %41
  br i1 %42, label %43, label %48

43:                                               ; preds = %36
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %12, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !9
  br label %50

48:                                               ; preds = %36
  %49 = load double, ptr %5, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %48, %43
  %51 = phi double [ %47, %43 ], [ %49, %48 ]
  store double %51, ptr %5, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %50
  %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 %31, !llvm.loop !13

55:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %56 = load double, ptr %5, align 8, !tbaa !9
  %57 = fcmp une double %56, 1.000000e+00
  %58 = zext i1 %57 to i32
  store i32 %58, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %64

61:                                               ; preds = %55
  %62 = load double, ptr %5, align 8, !tbaa !9
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %62)
  br label %66

64:                                               ; preds = %55
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %66

66:                                               ; preds = %64, %61
  %67 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %67, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %68 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %68)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %69 = load i32, ptr %1, align 4
  ret i32 %69
}

; 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
declare ptr @llvm.stacksave.p0() #2

; 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, ...) #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 = !{!10, !10, i64 0}
!10 = !{!"double", !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"

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

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 0, 2) i32 @main() local_unnamed_addr #0 {
vector.ph:
  %0 = alloca [100000 x double], align 16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.1, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 0, i64 1>, %vector.ph ], [ %vec.ind.next.1, %vector.body ]
  %1 = trunc <2 x i64> %vec.ind to <2 x i32>
  %2 = add <2 x i32> %1, <i32 1, i32 1>
  %3 = trunc <2 x i64> %vec.ind to <2 x i32>
  %4 = add <2 x i32> %3, <i32 3, i32 3>
  %5 = uitofp <2 x i32> %2 to <2 x double>
  %6 = uitofp <2 x i32> %4 to <2 x double>
  %7 = getelementptr inbounds double, ptr %0, i64 %index
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  store <2 x double> %5, ptr %7, align 16, !tbaa !5
  store <2 x double> %6, ptr %8, align 16, !tbaa !5
  %index.next = or disjoint i64 %index, 4
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 4, i64 4>
  %9 = trunc <2 x i64> %vec.ind.next to <2 x i32>
  %10 = add <2 x i32> %9, <i32 1, i32 1>
  %11 = trunc <2 x i64> %vec.ind.next to <2 x i32>
  %12 = add <2 x i32> %11, <i32 3, i32 3>
  %13 = uitofp <2 x i32> %10 to <2 x double>
  %14 = uitofp <2 x i32> %12 to <2 x double>
  %15 = getelementptr inbounds double, ptr %0, i64 %index.next
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <2 x double> %13, ptr %15, align 16, !tbaa !5
  store <2 x double> %14, ptr %16, align 16, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 8
  %vec.ind.next.1 = add <2 x i64> %vec.ind, <i64 8, i64 8>
  %17 = icmp eq i64 %index.next.1, 100000
  br i1 %17, label %.preheader, label %vector.body, !llvm.loop !9

18:                                               ; preds = %.preheader
  %19 = fcmp une double %..020.3, 1.000000e+00
  br i1 %19, label %32, label %34

.preheader:                                       ; preds = %vector.body, %.preheader
  %indvars.iv26 = phi i64 [ %indvars.iv.next27.3, %.preheader ], [ 0, %vector.body ]
  %.02023 = phi double [ %..020.3, %.preheader ], [ 1.000000e+05, %vector.body ]
  %20 = getelementptr inbounds double, ptr %0, i64 %indvars.iv26
  %21 = load double, ptr %20, align 16, !tbaa !5
  %22 = fcmp olt double %21, %.02023
  %..020 = select i1 %22, double %21, double %.02023
  %indvars.iv.next27 = or disjoint i64 %indvars.iv26, 1
  %23 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next27
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = fcmp olt double %24, %..020
  %..020.1 = select i1 %25, double %24, double %..020
  %indvars.iv.next27.1 = or disjoint i64 %indvars.iv26, 2
  %26 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next27.1
  %27 = load double, ptr %26, align 16, !tbaa !5
  %28 = fcmp olt double %27, %..020.1
  %..020.2 = select i1 %28, double %27, double %..020.1
  %indvars.iv.next27.2 = or disjoint i64 %indvars.iv26, 3
  %29 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next27.2
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = fcmp olt double %30, %..020.2
  %..020.3 = select i1 %31, double %30, double %..020.2
  %indvars.iv.next27.3 = add nuw nsw i64 %indvars.iv26, 4
  %exitcond29.not.3 = icmp eq i64 %indvars.iv.next27.3, 100000
  br i1 %exitcond29.not.3, label %18, label %.preheader, !llvm.loop !13

32:                                               ; preds = %18
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %..020.3)
  br label %36

34:                                               ; preds = %18
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %36

36:                                               ; preds = %34, %32
  %37 = zext i1 %19 to i32
  ret i32 %37
}

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

attributes #0 = { nofree 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 = !{!"double", !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}


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