; LLVM IR from pranjalwalia/Competitive-programming :: AtCoder/ABC/173/ABC.ll (Z5colorxx)

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

@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@b = external dso_local global [7 x [7 x i8]], align 16

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

10:                                               ; preds = %39, %2
  %11 = load i64, ptr %5, align 8, !tbaa !5
  %12 = load i64, ptr @n, align 8, !tbaa !5
  %13 = icmp slt i64 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %42

15:                                               ; preds = %10
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = trunc i64 %17 to i32
  %19 = shl i32 1, %18
  %20 = sext i32 %19 to i64
  %21 = and i64 %16, %20
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %38

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

24:                                               ; preds = %34, %23
  %25 = load i64, ptr %7, align 8, !tbaa !5
  %26 = load i64, ptr @m, align 8, !tbaa !5
  %27 = icmp slt i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %37

29:                                               ; preds = %24
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds [7 x [7 x i8]], ptr @b, i64 0, i64 %30
  %32 = load i64, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds [7 x i8], ptr %31, i64 0, i64 %32
  store i8 36, ptr %33, align 1, !tbaa !9
  br label %34

34:                                               ; preds = %29
  %35 = load i64, ptr %7, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %7, align 8, !tbaa !5
  br label %24, !llvm.loop !10

37:                                               ; preds = %28
  br label %38

38:                                               ; preds = %37, %15
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = add nsw i64 %40, 1
  store i64 %41, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !12

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

43:                                               ; preds = %72, %42
  %44 = load i64, ptr %8, align 8, !tbaa !5
  %45 = load i64, ptr @m, align 8, !tbaa !5
  %46 = icmp slt i64 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %75

48:                                               ; preds = %43
  %49 = load i64, ptr %4, align 8, !tbaa !5
  %50 = load i64, ptr %8, align 8, !tbaa !5
  %51 = trunc i64 %50 to i32
  %52 = shl i32 1, %51
  %53 = sext i32 %52 to i64
  %54 = and i64 %49, %53
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %56, label %71

56:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %67, %56
  %58 = load i64, ptr %9, align 8, !tbaa !5
  %59 = load i64, ptr @n, align 8, !tbaa !5
  %60 = icmp slt i64 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  store i32 11, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %70

62:                                               ; preds = %57
  %63 = load i64, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds [7 x [7 x i8]], ptr @b, i64 0, i64 %63
  %65 = load i64, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds [7 x i8], ptr %64, i64 0, i64 %65
  store i8 36, ptr %66, align 1, !tbaa !9
  br label %67

67:                                               ; preds = %62
  %68 = load i64, ptr %9, align 8, !tbaa !5
  %69 = add nsw i64 %68, 1
  store i64 %69, ptr %9, align 8, !tbaa !5
  br label %57, !llvm.loop !13

70:                                               ; preds = %61
  br label %71

71:                                               ; preds = %70, %48
  br label %72

72:                                               ; preds = %71
  %73 = load i64, ptr %8, align 8, !tbaa !5
  %74 = add nsw i64 %73, 1
  store i64 %74, ptr %8, align 8, !tbaa !5
  br label %43, !llvm.loop !14

75:                                               ; preds = %47
  ret void
}

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


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

@n = external dso_local local_unnamed_addr global i64, align 8
@m = external dso_local local_unnamed_addr global i64, align 8
@b = external dso_local local_unnamed_addr global [7 x [7 x i8]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z5colorxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr @n, align 8, !tbaa !5
  %.fr = freeze i64 %3
  %4 = icmp sgt i64 %.fr, 0
  %.pre = load i64, ptr @m, align 8
  %.fr32 = freeze i64 %.pre
  %5 = icmp sgt i64 %.fr32, 0
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %.lr.ph26.split.us.preheader, label %._crit_edge

.lr.ph26.split.us.preheader:                      ; preds = %2
  %xtraiter = and i64 %.fr, 1
  %6 = icmp eq i64 %.fr, 1
  br i1 %6, label %.preheader20.unr-lcssa, label %.lr.ph26.split.us.preheader.new

.lr.ph26.split.us.preheader.new:                  ; preds = %.lr.ph26.split.us.preheader
  %unroll_iter = and i64 %.fr, 9223372036854775806
  br label %.lr.ph26.split.us

.lr.ph26.split.us:                                ; preds = %..loopexit22_crit_edge.us.1, %.lr.ph26.split.us.preheader.new
  %.01824.us = phi i64 [ 0, %.lr.ph26.split.us.preheader.new ], [ %18, %..loopexit22_crit_edge.us.1 ]
  %niter = phi i64 [ 0, %.lr.ph26.split.us.preheader.new ], [ %niter.next.1, %..loopexit22_crit_edge.us.1 ]
  %7 = trunc i64 %.01824.us to i32
  %8 = shl nuw i32 1, %7
  %9 = zext nneg i32 %8 to i64
  %10 = and i64 %9, %0
  %.not19.us = icmp eq i64 %10, 0
  br i1 %.not19.us, label %..loopexit22_crit_edge.us, label %.preheader21.us.preheader

.preheader21.us.preheader:                        ; preds = %.lr.ph26.split.us
  %11 = mul nuw nsw i64 %.01824.us, 7
  %scevgep = getelementptr i8, ptr @b, i64 %11
  tail call void @llvm.memset.p0.i64(ptr align 2 %scevgep, i8 36, i64 %.fr32, i1 false), !tbaa !9
  br label %..loopexit22_crit_edge.us

..loopexit22_crit_edge.us:                        ; preds = %.preheader21.us.preheader, %.lr.ph26.split.us
  %12 = or disjoint i64 %.01824.us, 1
  %13 = trunc i64 %12 to i32
  %14 = shl nuw i32 1, %13
  %15 = sext i32 %14 to i64
  %16 = and i64 %15, %0
  %.not19.us.1 = icmp eq i64 %16, 0
  br i1 %.not19.us.1, label %..loopexit22_crit_edge.us.1, label %.preheader21.us.preheader.1

.preheader21.us.preheader.1:                      ; preds = %..loopexit22_crit_edge.us
  %17 = mul nuw nsw i64 %12, 7
  %scevgep.1 = getelementptr i8, ptr @b, i64 %17
  tail call void @llvm.memset.p0.i64(ptr align 1 %scevgep.1, i8 36, i64 %.fr32, i1 false), !tbaa !9
  br label %..loopexit22_crit_edge.us.1

..loopexit22_crit_edge.us.1:                      ; preds = %.preheader21.us.preheader.1, %..loopexit22_crit_edge.us
  %18 = add nuw nsw i64 %.01824.us, 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 %.preheader20.unr-lcssa, label %.lr.ph26.split.us, !llvm.loop !10

.preheader20.unr-lcssa:                           ; preds = %..loopexit22_crit_edge.us.1, %.lr.ph26.split.us.preheader
  %.01824.us.unr = phi i64 [ 0, %.lr.ph26.split.us.preheader ], [ %18, %..loopexit22_crit_edge.us.1 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader20, label %.lr.ph26.split.us.epil

.lr.ph26.split.us.epil:                           ; preds = %.preheader20.unr-lcssa
  %19 = trunc i64 %.01824.us.unr to i32
  %20 = shl nuw i32 1, %19
  %21 = sext i32 %20 to i64
  %22 = and i64 %21, %0
  %.not19.us.epil = icmp eq i64 %22, 0
  br i1 %.not19.us.epil, label %.preheader20, label %.preheader21.us.preheader.epil

.preheader21.us.preheader.epil:                   ; preds = %.lr.ph26.split.us.epil
  %23 = mul nuw nsw i64 %.01824.us.unr, 7
  %scevgep.epil = getelementptr i8, ptr @b, i64 %23
  tail call void @llvm.memset.p0.i64(ptr align 1 %scevgep.epil, i8 36, i64 %.fr32, i1 false), !tbaa !9
  br label %.preheader20

.preheader20:                                     ; preds = %.lr.ph26.split.us.epil, %.preheader21.us.preheader.epil, %.preheader20.unr-lcssa
  br i1 %4, label %.lr.ph30.split.us.preheader, label %._crit_edge

.lr.ph30.split.us.preheader:                      ; preds = %.preheader20
  %xtraiter39 = and i64 %.fr, 3
  %24 = icmp ult i64 %.fr, 4
  %unroll_iter41 = and i64 %.fr, 9223372036854775804
  %lcmp.mod40.not = icmp eq i64 %xtraiter39, 0
  br label %.lr.ph30.split.us

.lr.ph30.split.us:                                ; preds = %.lr.ph30.split.us.preheader, %..loopexit_crit_edge.us
  %.01628.us = phi i64 [ %39, %..loopexit_crit_edge.us ], [ 0, %.lr.ph30.split.us.preheader ]
  %25 = trunc i64 %.01628.us to i32
  %26 = shl nuw i32 1, %25
  %27 = sext i32 %26 to i64
  %28 = and i64 %27, %1
  %.not.us = icmp eq i64 %28, 0
  br i1 %.not.us, label %..loopexit_crit_edge.us, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.lr.ph30.split.us
  br i1 %24, label %..loopexit_crit_edge.us.loopexit.unr-lcssa, label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %.preheader.us
  %.027.us = phi i64 [ %36, %.preheader.us ], [ 0, %.preheader.us.preheader ]
  %niter42 = phi i64 [ %niter42.next.3, %.preheader.us ], [ 0, %.preheader.us.preheader ]
  %29 = getelementptr inbounds [7 x [7 x i8]], ptr @b, i64 0, i64 %.027.us, i64 %.01628.us
  store i8 36, ptr %29, align 1, !tbaa !9
  %30 = or disjoint i64 %.027.us, 1
  %31 = getelementptr inbounds [7 x [7 x i8]], ptr @b, i64 0, i64 %30, i64 %.01628.us
  store i8 36, ptr %31, align 1, !tbaa !9
  %32 = or disjoint i64 %.027.us, 2
  %33 = getelementptr inbounds [7 x [7 x i8]], ptr @b, i64 0, i64 %32, i64 %.01628.us
  store i8 36, ptr %33, align 1, !tbaa !9
  %34 = or disjoint i64 %.027.us, 3
  %35 = getelementptr inbounds [7 x [7 x i8]], ptr @b, i64 0, i64 %34, i64 %.01628.us
  store i8 36, ptr %35, align 1, !tbaa !9
  %36 = add nuw nsw i64 %.027.us, 4
  %niter42.next.3 = add i64 %niter42, 4
  %niter42.ncmp.3 = icmp eq i64 %niter42.next.3, %unroll_iter41
  br i1 %niter42.ncmp.3, label %..loopexit_crit_edge.us.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !12

..loopexit_crit_edge.us.loopexit.unr-lcssa:       ; preds = %.preheader.us, %.preheader.us.preheader
  %.027.us.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %36, %.preheader.us ]
  br i1 %lcmp.mod40.not, label %..loopexit_crit_edge.us, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %..loopexit_crit_edge.us.loopexit.unr-lcssa, %.preheader.us.epil
  %.027.us.epil = phi i64 [ %38, %.preheader.us.epil ], [ %.027.us.unr, %..loopexit_crit_edge.us.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.us.epil ], [ 0, %..loopexit_crit_edge.us.loopexit.unr-lcssa ]
  %37 = getelementptr inbounds [7 x [7 x i8]], ptr @b, i64 0, i64 %.027.us.epil, i64 %.01628.us
  store i8 36, ptr %37, align 1, !tbaa !9
  %38 = add nuw nsw i64 %.027.us.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter39
  br i1 %epil.iter.cmp.not, label %..loopexit_crit_edge.us, label %.preheader.us.epil, !llvm.loop !13

..loopexit_crit_edge.us:                          ; preds = %..loopexit_crit_edge.us.loopexit.unr-lcssa, %.preheader.us.epil, %.lr.ph30.split.us
  %39 = add nuw nsw i64 %.01628.us, 1
  %exitcond36.not = icmp eq i64 %39, %.fr32
  br i1 %exitcond36.not, label %._crit_edge, label %.lr.ph30.split.us, !llvm.loop !15

._crit_edge:                                      ; preds = %..loopexit_crit_edge.us, %.preheader20, %2
  ret void
}

; 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, argmem: none, 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !11}


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