; LLVM IR from Leet-Us-Code/DSA-A-Z-Practice :: Sid's Levels/Level - 2/Backtracking/MColourProblem.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 i32, align 4
  %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 %91

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 = %85, %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 %88

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !9
  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 %15, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [101 x i8], ptr %33, i64 %35
  %37 = load i32, ptr %11, 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 i32 1, ptr %14, align 4, !tbaa !9
  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 i32, ptr %14, align 4, !tbaa !9
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %81

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

75:                                               ; preds = %62
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %82

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

81:                                               ; preds = %76, %59
  store i32 0, ptr %13, align 4
  br label %82

82:                                               ; preds = %81, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  %83 = load i32, ptr %13, align 4
  switch i32 %83, label %88 [
    i32 0, label %84
  ]

84:                                               ; preds = %82
  br label %85

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

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

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

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

93:                                               ; preds = %88
  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 %indvars.iv, i64 %7
  %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