; LLVM IR from tangjz/acm-icpc :: 51nod/1562.ll (Z10radix_sortiPii)

; 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"

@_ZZ10radix_sortiPiiE3cnt = external hidden global [200001 x i32], align 16

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

10:                                               ; preds = %19, %3
  %11 = load i32, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp sle 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 %22

15:                                               ; preds = %10
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %17
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %15
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %7, align 4, !tbaa !5
  br label %10, !llvm.loop !11

22:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %38, %22
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %41

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %35, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %28
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !5
  br label %23, !llvm.loop !13

41:                                               ; preds = %27
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %61, %41
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = icmp sle i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %64

47:                                               ; preds = %42
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %60

53:                                               ; preds = %47
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !9
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds i32, ptr %55, i64 %58
  store i32 %54, ptr %59, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %53, %47
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %9, align 4, !tbaa !5
  br label %42, !llvm.loop !14

64:                                               ; preds = %46
  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 = !{!"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"

@_ZZ10radix_sortiPiiE3cnt = external hidden local_unnamed_addr global [200001 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z10radix_sortiPii(i32 noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not22 = icmp slt i32 %2, 0
  br i1 %.not22, label %.preheader21, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %4 = add nuw i32 %2, 1
  %5 = zext i32 %4 to i64
  %6 = shl nuw nsw i64 %5, 2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) @_ZZ10radix_sortiPiiE3cnt, i8 0, i64 %6, i1 false), !tbaa !5
  br label %.preheader21

.preheader21:                                     ; preds = %.lr.ph.preheader, %3
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph25.preheader, label %.preheader

.lr.ph25.preheader:                               ; preds = %.preheader21
  %wide.trip.count = zext nneg i32 %0 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %8 = icmp ult i32 %0, 4
  br i1 %8, label %.preheader.loopexit.unr-lcssa, label %.lr.ph25.preheader.new

.lr.ph25.preheader.new:                           ; preds = %.lr.ph25.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph25

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph25, %.lr.ph25.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph25.preheader ], [ %indvars.iv.next.3, %.lr.ph25 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph25.epil

.lr.ph25.epil:                                    ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph25.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph25.epil ], [ %indvars.iv.unr, %.preheader.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph25.epil ], [ 0, %.preheader.loopexit.unr-lcssa ]
  %9 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.epil
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader, label %.lr.ph25.epil, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph25.epil, %.preheader21
  br i1 %.not22, label %._crit_edge, label %.lr.ph29.preheader

.lr.ph29.preheader:                               ; preds = %.preheader
  %15 = add nuw i32 %2, 1
  %wide.trip.count35 = zext i32 %15 to i64
  %xtraiter37 = and i64 %wide.trip.count35, 1
  %16 = icmp eq i32 %2, 0
  br i1 %16, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph29.preheader.new

.lr.ph29.preheader.new:                           ; preds = %.lr.ph29.preheader
  %unroll_iter40 = and i64 %wide.trip.count35, 4294967294
  br label %.lr.ph29

.lr.ph25:                                         ; preds = %.lr.ph25, %.lr.ph25.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %indvars.iv.next.3, %.lr.ph25 ]
  %niter = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %niter.next.3, %.lr.ph25 ]
  %17 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %26, align 4, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %29 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.1
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %32, align 4, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %35 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.2
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader.loopexit.unr-lcssa, label %.lr.ph25, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %61
  %41 = sext i32 %.1.1 to i64
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph29.preheader
  %indvars.iv32.unr = phi i64 [ 0, %.lr.ph29.preheader ], [ %indvars.iv.next33.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.01727.unr = phi i64 [ 0, %.lr.ph29.preheader ], [ %41, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod39.not = icmp eq i64 %xtraiter37, 0
  br i1 %lcmp.mod39.not, label %._crit_edge, label %.lr.ph29.epil

.lr.ph29.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %42 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %indvars.iv32.unr
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %.not20.epil = icmp eq i32 %43, 0
  br i1 %.not20.epil, label %._crit_edge, label %44

44:                                               ; preds = %.lr.ph29.epil
  %45 = getelementptr inbounds i32, ptr %1, i64 %.01727.unr
  %46 = trunc nuw nsw i64 %indvars.iv32.unr to i32
  store i32 %46, ptr %45, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %44, %.lr.ph29.epil, %.preheader
  ret void

.lr.ph29:                                         ; preds = %61, %.lr.ph29.preheader.new
  %indvars.iv32 = phi i64 [ 0, %.lr.ph29.preheader.new ], [ %indvars.iv.next33.1, %61 ]
  %.01727 = phi i32 [ 0, %.lr.ph29.preheader.new ], [ %.1.1, %61 ]
  %niter41 = phi i64 [ 0, %.lr.ph29.preheader.new ], [ %niter41.next.1, %61 ]
  %47 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %indvars.iv32
  %48 = load i32, ptr %47, align 8, !tbaa !5
  %.not20 = icmp eq i32 %48, 0
  br i1 %.not20, label %.lr.ph29.1, label %49

49:                                               ; preds = %.lr.ph29
  %50 = add nsw i32 %.01727, 1
  %51 = sext i32 %.01727 to i64
  %52 = getelementptr inbounds i32, ptr %1, i64 %51
  %53 = trunc nuw nsw i64 %indvars.iv32 to i32
  store i32 %53, ptr %52, align 4, !tbaa !5
  br label %.lr.ph29.1

.lr.ph29.1:                                       ; preds = %.lr.ph29, %49
  %.1 = phi i32 [ %50, %49 ], [ %.01727, %.lr.ph29 ]
  %indvars.iv.next33 = or disjoint i64 %indvars.iv32, 1
  %54 = getelementptr inbounds [200001 x i32], ptr @_ZZ10radix_sortiPiiE3cnt, i64 0, i64 %indvars.iv.next33
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %.not20.1 = icmp eq i32 %55, 0
  br i1 %.not20.1, label %61, label %56

56:                                               ; preds = %.lr.ph29.1
  %57 = add nsw i32 %.1, 1
  %58 = sext i32 %.1 to i64
  %59 = getelementptr inbounds i32, ptr %1, i64 %58
  %60 = trunc nuw nsw i64 %indvars.iv.next33 to i32
  store i32 %60, ptr %59, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %56, %.lr.ph29.1
  %.1.1 = phi i32 [ %57, %56 ], [ %.1, %.lr.ph29.1 ]
  %indvars.iv.next33.1 = add nuw nsw i64 %indvars.iv32, 2
  %niter41.next.1 = add i64 %niter41, 2
  %niter41.ncmp.1 = icmp eq i64 %niter41.next.1, %unroll_iter40
  br i1 %niter41.ncmp.1, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph29, !llvm.loop !13
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: write) }

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


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass