; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Sorting Algorithms/bucket_sort.ll (Z14Insertion_SortPA10_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: mustprogress nounwind uwtable
define dso_local void @_Z14Insertion_SortPA10_fii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %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 float, 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
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %78, %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 %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %81

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %16 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %16, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10 x float], ptr %17, i64 %19
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [10 x float], ptr %20, i64 0, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !11
  store float %24, ptr %9, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %50, %15
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = sub nsw i32 %26, 1
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %29, label %48

29:                                               ; preds = %25
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [10 x float], ptr %30, i64 %32
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10 x float], ptr %33, i64 0, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !11
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [10 x float], ptr %38, i64 %40
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = sub nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [10 x float], ptr %41, i64 0, i64 %44
  %46 = load float, ptr %45, align 4, !tbaa !11
  %47 = fcmp olt float %37, %46
  br label %48

48:                                               ; preds = %29, %25
  %49 = phi i1 [ false, %25 ], [ %47, %29 ]
  br i1 %49, label %50, label %69

50:                                               ; preds = %48
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [10 x float], ptr %51, i64 %53
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = sub nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [10 x float], ptr %54, i64 0, i64 %57
  %59 = load float, ptr %58, align 4, !tbaa !11
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [10 x float], ptr %60, i64 %62
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [10 x float], ptr %63, i64 0, i64 %65
  store float %59, ptr %66, align 4, !tbaa !11
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = sub nsw i32 %67, 1
  store i32 %68, ptr %8, align 4, !tbaa !9
  br label %25, !llvm.loop !13

69:                                               ; preds = %48
  %70 = load float, ptr %9, align 4, !tbaa !11
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [10 x float], ptr %71, i64 %73
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [10 x float], ptr %74, i64 0, i64 %76
  store float %70, ptr %77, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %78

78:                                               ; preds = %69
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %7, align 4, !tbaa !9
  br label %10, !llvm.loop !15

81:                                               ; preds = %14
  ret void
}

; 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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 memory(argmem: readwrite) uwtable
define dso_local void @_Z14Insertion_SortPA10_fii(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %.lr.ph31, label %._crit_edge

.lr.ph31:                                         ; preds = %3
  %5 = sext i32 %2 to i64
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %6

._crit_edge:                                      ; preds = %.critedge, %3
  ret void

6:                                                ; preds = %.lr.ph31, %.critedge
  %indvars.iv = phi i64 [ 0, %.lr.ph31 ], [ %indvars.iv.next, %.critedge ]
  %7 = getelementptr inbounds [10 x float], ptr %0, i64 %5, i64 %indvars.iv
  %8 = load float, ptr %7, align 4, !tbaa !5
  %.not = icmp eq i64 %indvars.iv, 0
  br i1 %.not, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %15
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %15 ], [ %indvars.iv, %6 ]
  %indvars.iv.next33 = add nsw i64 %indvars.iv32, -1
  %9 = getelementptr inbounds [10 x float], ptr %0, i64 %5, i64 %indvars.iv32
  %10 = load float, ptr %9, align 4, !tbaa !5
  %11 = and i64 %indvars.iv.next33, 4294967295
  %12 = getelementptr inbounds [10 x float], ptr %0, i64 %5, i64 %11
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = fcmp olt float %10, %13
  br i1 %14, label %15, label %.critedge

15:                                               ; preds = %.lr.ph
  store float %13, ptr %9, align 4, !tbaa !5
  %16 = icmp sgt i64 %indvars.iv32, 1
  br i1 %16, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %15, %6
  %.024.lcssa = phi i64 [ 0, %6 ], [ 0, %15 ], [ %indvars.iv32, %.lr.ph ]
  %sext = shl i64 %.024.lcssa, 32
  %17 = ashr exact i64 %sext, 32
  %18 = getelementptr inbounds [10 x float], ptr %0, i64 %5, i64 %17
  store float %8, ptr %18, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %6, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass