; LLVM IR from UtkarshPathrabe/Competitive-Coding :: Model Algorithms/Backtracking/Graph Coloring.ll (Z17GraphColorUtilityi)

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

@V = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@Color = external dso_local global [100 x i32], 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
declare dso_local noundef zeroext i1 @_Z6IsSafeii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z17GraphColorUtilityi(i32 noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr @V, align 4, !tbaa !5
  %8 = icmp eq i32 %6, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i1 true, ptr %2, align 1
  br label %41

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %35, %10
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr @M, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %5, align 4
  br label %38

16:                                               ; preds = %11
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = call noundef zeroext i1 @_Z6IsSafeii(i32 noundef %17, i32 noundef %18)
  br i1 %19, label %20, label %34

20:                                               ; preds = %16
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100 x i32], ptr @Color, i64 0, i64 %23
  store i32 %21, ptr %24, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = call noundef zeroext i1 @_Z17GraphColorUtilityi(i32 noundef %26)
  br i1 %27, label %28, label %29

28:                                               ; preds = %20
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %38

29:                                               ; preds = %20
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100 x i32], ptr @Color, i64 0, i64 %31
  store i32 0, ptr %32, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %29
  br label %34

34:                                               ; preds = %33, %16
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !9

38:                                               ; preds = %28, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %39 = load i32, ptr %5, align 4
  switch i32 %39, label %43 [
    i32 2, label %40
    i32 1, label %41
  ]

40:                                               ; preds = %38
  store i1 false, ptr %2, align 1
  br label %41

41:                                               ; preds = %40, %38, %9
  %42 = load i1, ptr %2, align 1
  ret i1 %42

43:                                               ; preds = %38
  unreachable
}

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 = { mustprogress 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 #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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@V = external dso_local local_unnamed_addr global i32, align 4
@M = external dso_local local_unnamed_addr global i32, align 4
@Color = external dso_local local_unnamed_addr global [100 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6IsSafeii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z17GraphColorUtilityi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @V, align 4, !tbaa !5
  %3 = icmp eq i32 %2, %0
  br i1 %3, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %4 = load i32, ptr @M, align 4, !tbaa !5
  %.not13 = icmp sgt i32 %4, 0
  br i1 %.not13, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [100 x i32], ptr @Color, i64 0, i64 %5
  %7 = add nsw i32 %0, 1
  br label %8

8:                                                ; preds = %.lr.ph, %13
  %.01014 = phi i32 [ 1, %.lr.ph ], [ %14, %13 ]
  %9 = tail call noundef zeroext i1 @_Z6IsSafeii(i32 noundef %0, i32 noundef %.01014)
  br i1 %9, label %10, label %13

10:                                               ; preds = %8
  store i32 %.01014, ptr %6, align 4, !tbaa !5
  %11 = tail call noundef zeroext i1 @_Z17GraphColorUtilityi(i32 noundef %7)
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %10
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %8, %12
  %14 = add nuw nsw i32 %.01014, 1
  %15 = load i32, ptr @M, align 4, !tbaa !5
  %.not = icmp slt i32 %.01014, %15
  br i1 %.not, label %8, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %10, %13, %.preheader, %1
  %.1 = phi i1 [ true, %1 ], [ false, %.preheader ], [ true, %10 ], [ false, %13 ]
  ret i1 %.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" }

!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.mustprogress"}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass