; LLVM IR from Leet-Us-Code/DSA-A-Z-Practice :: Sid's Levels/InterviewBit/Backtracking/M-Coloring Problem.ll (Z6helperPA101_biiPii)

; 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 uwtable
define dso_local noundef zeroext i1 @_Z6helperPA101_biiPii(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  %16 = load i32, ptr %11, align 4, !tbaa !9
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %5
  store i1 true, ptr %6, align 1
  br label %93

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

21:                                               ; preds = %87, %20
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 2, ptr %13, align 4
  br label %90

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #2
  store i8 1, ptr %14, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %55, %26
  %28 = load i32, ptr %15, align 4, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 5, ptr %13, align 4
  br label %58

32:                                               ; preds = %27
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [101 x i8], ptr %33, i64 %35
  %37 = load i32, ptr %15, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [101 x i8], ptr %36, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11, !range !13, !noundef !14
  %41 = trunc i8 %40 to i1
  %42 = zext i1 %41 to i32
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %44, label %54

44:                                               ; preds = %32
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = load i32, ptr %15, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %45, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = icmp eq i32 %49, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %44
  store i8 0, ptr %14, align 1, !tbaa !11
  store i32 5, ptr %13, align 4
  br label %58

53:                                               ; preds = %44
  br label %54

54:                                               ; preds = %53, %32
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %15, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %15, align 4, !tbaa !9
  br label %27, !llvm.loop !15

58:                                               ; preds = %52, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  br label %59

59:                                               ; preds = %58
  %60 = load i8, ptr %14, align 1, !tbaa !11, !range !13, !noundef !14
  %61 = trunc i8 %60 to i1
  %62 = zext i1 %61 to i32
  %63 = icmp eq i32 %62, 1
  br i1 %63, label %64, label %83

64:                                               ; preds = %59
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  store i32 %65, ptr %69, align 4, !tbaa !9
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = load i32, ptr %11, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  %76 = call noundef zeroext i1 @_Z6helperPA101_biiPii(ptr noundef %70, i32 noundef %71, i32 noundef %72, ptr noundef %73, i32 noundef %75)
  br i1 %76, label %77, label %78

77:                                               ; preds = %64
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %84

78:                                               ; preds = %64
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i32, ptr %79, i64 %81
  store i32 -1, ptr %82, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %78, %59
  store i32 0, ptr %13, align 4
  br label %84

84:                                               ; preds = %83, %77
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #2
  %85 = load i32, ptr %13, align 4
  switch i32 %85, label %90 [
    i32 0, label %86
  ]

86:                                               ; preds = %84
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %12, align 4, !tbaa !9
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %12, align 4, !tbaa !9
  br label %21, !llvm.loop !17

90:                                               ; preds = %84, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %91 = load i32, ptr %13, align 4
  switch i32 %91, label %95 [
    i32 2, label %92
    i32 1, label %93
  ]

92:                                               ; preds = %90
  store i1 false, ptr %6, align 1
  br label %93

93:                                               ; preds = %92, %90, %19
  %94 = load i1, ptr %6, align 1
  ret i1 %94

95:                                               ; preds = %90
  unreachable
}

; 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 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 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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 nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @_Z6helperPA101_biiPii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq i32 %4, %2
  br i1 %6, label %.critedge36, label %.preheader38

.preheader38:                                     ; preds = %5
  %.not3741 = icmp sgt i32 %1, 0
  br i1 %.not3741, label %.preheader.lr.ph, label %.critedge36

.preheader.lr.ph:                                 ; preds = %.preheader38
  %.not39 = icmp sgt i32 %2, 0
  %7 = sext i32 %4 to i64
  %8 = getelementptr inbounds i32, ptr %3, i64 %7
  %9 = add nsw i32 %4, 1
  br i1 %.not39, label %.preheader.us.preheader, label %.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %.loopexit.us
  %.02942.us = phi i32 [ %20, %.loopexit.us ], [ 0, %.preheader.us.preheader ]
  br label %11

10:                                               ; preds = %..critedge_crit_edge.us
  store i32 -1, ptr %8, align 4, !tbaa !5
  br label %.loopexit.us

11:                                               ; preds = %.preheader.us, %19
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %19 ]
  %12 = getelementptr inbounds [101 x i8], ptr %0, i64 %7, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !9, !range !11, !noundef !12
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %15, label %19

15:                                               ; preds = %11
  %16 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp eq i32 %17, %.02942.us
  br i1 %18, label %.loopexit.us, label %19

19:                                               ; preds = %15, %11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond48.not, label %..critedge_crit_edge.us, label %11, !llvm.loop !13

.loopexit.us:                                     ; preds = %15, %10
  %20 = add nuw nsw i32 %.02942.us, 1
  %exitcond49.not = icmp eq i32 %20, %1
  br i1 %exitcond49.not, label %.critedge36, label %.preheader.us, !llvm.loop !15

..critedge_crit_edge.us:                          ; preds = %19
  store i32 %.02942.us, ptr %8, align 4, !tbaa !5
  %21 = tail call noundef zeroext i1 @_Z6helperPA101_biiPii(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %9)
  br i1 %21, label %.critedge36, label %10

.preheader:                                       ; preds = %.preheader.lr.ph, %23
  %.02942 = phi i32 [ %24, %23 ], [ 0, %.preheader.lr.ph ]
  store i32 %.02942, ptr %8, align 4, !tbaa !5
  %22 = tail call noundef zeroext i1 @_Z6helperPA101_biiPii(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %9)
  br i1 %22, label %.critedge36, label %23

23:                                               ; preds = %.preheader
  store i32 -1, ptr %8, align 4, !tbaa !5
  %24 = add nuw nsw i32 %.02942, 1
  %exitcond.not = icmp eq i32 %24, %1
  br i1 %exitcond.not, label %.critedge36, label %.preheader, !llvm.loop !15

.critedge36:                                      ; preds = %.preheader, %23, %..critedge_crit_edge.us, %.loopexit.us, %.preheader38, %5
  %.3 = phi i1 [ true, %5 ], [ false, %.preheader38 ], [ true, %..critedge_crit_edge.us ], [ false, %.loopexit.us ], [ %22, %23 ], [ %22, %.preheader ]
  ret i1 %.3
}

attributes #0 = { mustprogress nofree 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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