; LLVM IR from DeanoC/gfx_imagecompress :: src/amd_hdr_encode.ll (ZN10HDR_Encode10all_same_dEPA4_fii)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

10:                                               ; preds = %45, %3
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %48

14:                                               ; preds = %10
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %41, %14
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %44

19:                                               ; preds = %15
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %38

22:                                               ; preds = %19
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds [4 x float], ptr %23, i64 0
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4 x float], ptr %24, i64 0, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !11
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4 x float], ptr %29, i64 %31
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [4 x float], ptr %32, i64 0, i64 %34
  %36 = load float, ptr %35, align 4, !tbaa !11
  %37 = fcmp oeq float %28, %36
  br label %38

38:                                               ; preds = %22, %19
  %39 = phi i1 [ false, %19 ], [ %37, %22 ]
  %40 = zext i1 %39 to i32
  store i32 %40, ptr %9, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !9
  br label %15, !llvm.loop !13

44:                                               ; preds = %15
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !9
  br label %10, !llvm.loop !15

48:                                               ; preds = %10
  %49 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %49
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN10HDR_Encode10all_same_dEPA4_fii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %1, 1
  %5 = icmp sgt i32 %2, 0
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge18

.preheader.us.preheader:                          ; preds = %3
  %wide.trip.count25 = zext nneg i32 %1 to i64
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %6 = icmp eq i32 %2, 1
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv22 = phi i64 [ 1, %.preheader.us.preheader ], [ %indvars.iv.next23, %._crit_edge.us ]
  %.017.us = phi i32 [ 1, %.preheader.us.preheader ], [ %.lcssa, %._crit_edge.us ]
  br i1 %6, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.critedge
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.critedge ], [ 0, %.preheader.us ]
  %.115.us = phi i32 [ %20, %.critedge ], [ %.017.us, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.critedge ], [ 0, %.preheader.us ]
  %.not.us = icmp eq i32 %.115.us, 0
  br i1 %.not.us, label %.critedge, label %7

7:                                                ; preds = %.preheader.us.new
  %8 = getelementptr inbounds [4 x float], ptr %0, i64 0, i64 %indvars.iv
  %9 = load float, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds [4 x float], ptr %0, i64 %indvars.iv22, i64 %indvars.iv
  %11 = load float, ptr %10, align 4, !tbaa !5
  %12 = fcmp oeq float %9, %11
  br i1 %12, label %13, label %.critedge

13:                                               ; preds = %7
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %14 = getelementptr inbounds [4 x float], ptr %0, i64 0, i64 %indvars.iv.next
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = getelementptr inbounds [4 x float], ptr %0, i64 %indvars.iv22, i64 %indvars.iv.next
  %17 = load float, ptr %16, align 4, !tbaa !5
  %18 = fcmp oeq float %15, %17
  br label %.critedge

.critedge:                                        ; preds = %.preheader.us.new, %13, %7
  %19 = phi i1 [ false, %7 ], [ %18, %13 ], [ false, %.preheader.us.new ]
  %20 = zext i1 %19 to i32
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.critedge, %.preheader.us
  %.lcssa.ph = phi i32 [ poison, %.preheader.us ], [ %20, %.critedge ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %.critedge ]
  %.115.us.unr = phi i32 [ %.017.us, %.preheader.us ], [ %20, %.critedge ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %.not.us.epil = icmp eq i32 %.115.us.unr, 0
  br i1 %.not.us.epil, label %._crit_edge.us.epilog-lcssa, label %21

21:                                               ; preds = %.epil.preheader
  %22 = getelementptr inbounds [4 x float], ptr %0, i64 0, i64 %indvars.iv.unr
  %23 = load float, ptr %22, align 4, !tbaa !5
  %24 = getelementptr inbounds [4 x float], ptr %0, i64 %indvars.iv22, i64 %indvars.iv.unr
  %25 = load float, ptr %24, align 4, !tbaa !5
  %26 = fcmp oeq float %23, %25
  br label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %21, %.epil.preheader
  %27 = phi i1 [ false, %.epil.preheader ], [ %26, %21 ]
  %28 = zext i1 %27 to i32
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %28, %._crit_edge.us.epilog-lcssa ]
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %exitcond26.not = icmp eq i64 %indvars.iv.next23, %wide.trip.count25
  br i1 %exitcond26.not, label %._crit_edge18, label %.preheader.us, !llvm.loop !11

._crit_edge18:                                    ; preds = %._crit_edge.us, %3
  %.0.lcssa = phi i32 [ 1, %3 ], [ %.lcssa, %._crit_edge.us ]
  ret i32 %.0.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass