; LLVM IR from wuzhouhui/leetcode :: 75_sort_colors (sortColors)

; 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: nounwind uwtable
define dso_local void @sortColors(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [3 x i32], align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %2
  br label %60

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 12, ptr %5) #3
  call void @llvm.memset.p0.i64(ptr align 4 %5, i8 0, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %30, %15
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %33

20:                                               ; preds = %16
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [3 x i32], ptr %5, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %27, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %20
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %6, align 4, !tbaa !9
  br label %16, !llvm.loop !11

33:                                               ; preds = %16
  store i32 0, ptr %6, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %56, %33
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = icmp slt i32 %35, 3
  br i1 %36, label %37, label %59

37:                                               ; preds = %34
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %52, %37
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [3 x i32], ptr %5, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = icmp slt i32 %39, %43
  br i1 %44, label %45, label %55

45:                                               ; preds = %38
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !9
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds i32, ptr %47, i64 %50
  store i32 %46, ptr %51, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %45
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !9
  br label %38, !llvm.loop !13

55:                                               ; preds = %38
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %6, align 4, !tbaa !9
  br label %34, !llvm.loop !14

59:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %5) #3
  br label %60

60:                                               ; preds = %59, %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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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 nounwind willreturn memory(argmem: write) }
attributes #3 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @sortColors(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [3 x i32], align 4
  %or.cond = icmp ult i32 %1, 2
  br i1 %or.cond, label %59, label %4

4:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %3, i8 0, i64 12, i1 false)
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %6 = icmp ult i32 %1, 4
  br i1 %6, label %.preheader19.unr-lcssa, label %.lr.ph.preheader.new

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

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

.lr.ph.epil:                                      ; preds = %.preheader19.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.preheader19.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader19.unr-lcssa ]
  %7 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.epil
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [3 x i32], ptr %3, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %10, 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 %.preheader19, label %.lr.ph.epil, !llvm.loop !9

.preheader19:                                     ; preds = %.lr.ph.epil, %.preheader19.unr-lcssa
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  %13 = icmp sgt i32 %.pre, 0
  br i1 %13, label %.lr.ph23.preheader, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %14 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [3 x i32], ptr %3, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %17, align 4, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %20 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [3 x i32], ptr %3, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %26 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.1
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [3 x i32], ptr %3, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %29, align 4, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %32 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.2
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [3 x i32], ptr %3, 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
  %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 %.preheader19.unr-lcssa, label %.lr.ph, !llvm.loop !11

.lr.ph23.preheader:                               ; preds = %.preheader19
  %38 = zext nneg i32 %.pre to i64
  %39 = shl nuw nsw i64 %38, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %0, i8 0, i64 %39, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %4, %.lr.ph23.preheader, %.preheader19
  %.1.lcssa = phi i32 [ 0, %.preheader19 ], [ %.pre, %.lr.ph23.preheader ], [ 0, %4 ]
  %40 = getelementptr inbounds i8, ptr %3, i64 4
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp sgt i32 %41, 0
  br i1 %42, label %.lr.ph23.preheader.1, label %._crit_edge.1

.lr.ph23.preheader.1:                             ; preds = %._crit_edge
  %43 = zext nneg i32 %.1.lcssa to i64
  %44 = zext nneg i32 %41 to i64
  %min.iters.check = icmp ult i32 %41, 8
  br i1 %min.iters.check, label %.lr.ph23.1.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph23.preheader.1
  %n.vec = and i64 %44, 2147483640
  %ind.end = add nuw nsw i64 %n.vec, %43
  %ind.end36 = trunc nuw nsw i64 %n.vec to i32
  %invariant.gep = getelementptr i32, ptr %0, i64 %43
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %gep = getelementptr i32, ptr %invariant.gep, i64 %index
  %45 = getelementptr inbounds i8, ptr %gep, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %gep, align 4, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %45, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %46 = icmp eq i64 %index.next, %n.vec
  br i1 %46, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %44
  br i1 %cmp.n, label %._crit_edge.loopexit.1, label %.lr.ph23.1.preheader

.lr.ph23.1.preheader:                             ; preds = %middle.block, %.lr.ph23.preheader.1
  %indvars.iv27.1.ph = phi i64 [ %43, %.lr.ph23.preheader.1 ], [ %ind.end, %middle.block ]
  %.01521.1.ph = phi i32 [ 0, %.lr.ph23.preheader.1 ], [ %ind.end36, %middle.block ]
  br label %.lr.ph23.1

.lr.ph23.1:                                       ; preds = %.lr.ph23.1.preheader, %.lr.ph23.1
  %indvars.iv27.1 = phi i64 [ %indvars.iv.next28.1, %.lr.ph23.1 ], [ %indvars.iv27.1.ph, %.lr.ph23.1.preheader ]
  %.01521.1 = phi i32 [ %48, %.lr.ph23.1 ], [ %.01521.1.ph, %.lr.ph23.1.preheader ]
  %indvars.iv.next28.1 = add nuw nsw i64 %indvars.iv27.1, 1
  %47 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv27.1
  store i32 1, ptr %47, align 4, !tbaa !5
  %48 = add nuw nsw i32 %.01521.1, 1
  %exitcond30.1.not = icmp eq i32 %48, %41
  br i1 %exitcond30.1.not, label %._crit_edge.loopexit.1, label %.lr.ph23.1, !llvm.loop !16

._crit_edge.loopexit.1:                           ; preds = %.lr.ph23.1, %middle.block
  %indvars.iv.next28.1.lcssa = phi i64 [ %ind.end, %middle.block ], [ %indvars.iv.next28.1, %.lr.ph23.1 ]
  %49 = trunc nsw i64 %indvars.iv.next28.1.lcssa to i32
  br label %._crit_edge.1

._crit_edge.1:                                    ; preds = %._crit_edge.loopexit.1, %._crit_edge
  %.1.lcssa.1 = phi i32 [ %.1.lcssa, %._crit_edge ], [ %49, %._crit_edge.loopexit.1 ]
  %50 = getelementptr inbounds i8, ptr %3, i64 8
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %.lr.ph23.preheader.2, label %._crit_edge.2

.lr.ph23.preheader.2:                             ; preds = %._crit_edge.1
  %53 = sext i32 %.1.lcssa.1 to i64
  %54 = zext nneg i32 %51 to i64
  %min.iters.check40 = icmp ult i32 %51, 8
  br i1 %min.iters.check40, label %.lr.ph23.2.preheader, label %vector.ph41

vector.ph41:                                      ; preds = %.lr.ph23.preheader.2
  %n.vec43 = and i64 %54, 2147483640
  %ind.end44 = add nsw i64 %n.vec43, %53
  %ind.end46 = trunc nuw nsw i64 %n.vec43 to i32
  %invariant.gep55 = getelementptr i32, ptr %0, i64 %53
  br label %vector.body48

vector.body48:                                    ; preds = %vector.body48, %vector.ph41
  %index49 = phi i64 [ 0, %vector.ph41 ], [ %index.next51, %vector.body48 ]
  %gep56 = getelementptr i32, ptr %invariant.gep55, i64 %index49
  %55 = getelementptr inbounds i8, ptr %gep56, i64 16
  store <4 x i32> <i32 2, i32 2, i32 2, i32 2>, ptr %gep56, align 4, !tbaa !5
  store <4 x i32> <i32 2, i32 2, i32 2, i32 2>, ptr %55, align 4, !tbaa !5
  %index.next51 = add nuw i64 %index49, 8
  %56 = icmp eq i64 %index.next51, %n.vec43
  br i1 %56, label %middle.block38, label %vector.body48, !llvm.loop !17

middle.block38:                                   ; preds = %vector.body48
  %cmp.n52 = icmp eq i64 %n.vec43, %54
  br i1 %cmp.n52, label %._crit_edge.2, label %.lr.ph23.2.preheader

.lr.ph23.2.preheader:                             ; preds = %middle.block38, %.lr.ph23.preheader.2
  %indvars.iv27.2.ph = phi i64 [ %53, %.lr.ph23.preheader.2 ], [ %ind.end44, %middle.block38 ]
  %.01521.2.ph = phi i32 [ 0, %.lr.ph23.preheader.2 ], [ %ind.end46, %middle.block38 ]
  br label %.lr.ph23.2

.lr.ph23.2:                                       ; preds = %.lr.ph23.2.preheader, %.lr.ph23.2
  %indvars.iv27.2 = phi i64 [ %indvars.iv.next28.2, %.lr.ph23.2 ], [ %indvars.iv27.2.ph, %.lr.ph23.2.preheader ]
  %.01521.2 = phi i32 [ %58, %.lr.ph23.2 ], [ %.01521.2.ph, %.lr.ph23.2.preheader ]
  %indvars.iv.next28.2 = add nsw i64 %indvars.iv27.2, 1
  %57 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv27.2
  store i32 2, ptr %57, align 4, !tbaa !5
  %58 = add nuw nsw i32 %.01521.2, 1
  %exitcond30.2.not = icmp eq i32 %58, %51
  br i1 %exitcond30.2.not, label %._crit_edge.2, label %.lr.ph23.2, !llvm.loop !18

._crit_edge.2:                                    ; preds = %.lr.ph23.2, %middle.block38, %._crit_edge.1
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #3
  br label %59

59:                                               ; preds = %2, %._crit_edge.2
  ret void
}

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

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

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

attributes #0 = { 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12, !14, !15}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !12, !15, !14}
!17 = distinct !{!17, !12, !14, !15}
!18 = distinct !{!18, !12, !15, !14}


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