; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C/Algorithms/Graph-Algorithms (Breadth_first_search)

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

@i = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [20 x [20 x i32]], align 16
@visited = external dso_local global [20 x i32], align 16
@q = external dso_local global [20 x i32], align 16
@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [36 x i8], align 1
@j = external dso_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @bfs(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @main() #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %2 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n)
  store i32 1, ptr @i, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %15, %0
  %5 = load i32, ptr @i, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sle i32 %5, %6
  br i1 %7, label %8, label %18

8:                                                ; preds = %4
  %9 = load i32, ptr @i, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [20 x i32], ptr @q, i64 0, i64 %10
  store i32 0, ptr %11, align 4, !tbaa !5
  %12 = load i32, ptr @i, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [20 x i32], ptr @visited, i64 0, i64 %13
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %8
  %16 = load i32, ptr @i, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @i, align 4, !tbaa !5
  br label %4, !llvm.loop !9

18:                                               ; preds = %4
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 1, ptr @i, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %41, %18
  %21 = load i32, ptr @i, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %24, label %44

24:                                               ; preds = %20
  store i32 1, ptr @j, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %37, %24
  %26 = load i32, ptr @j, align 4, !tbaa !5
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = icmp sle i32 %26, %27
  br i1 %28, label %29, label %40

29:                                               ; preds = %25
  %30 = load i32, ptr @i, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [20 x [20 x i32]], ptr @a, i64 0, i64 %31
  %33 = load i32, ptr @j, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [20 x i32], ptr %32, i64 0, i64 %34
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %35)
  br label %37

37:                                               ; preds = %29
  %38 = load i32, ptr @j, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr @j, align 4, !tbaa !5
  br label %25, !llvm.loop !11

40:                                               ; preds = %25
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr @i, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr @i, align 4, !tbaa !5
  br label %20, !llvm.loop !12

44:                                               ; preds = %20
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %46 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %1)
  %47 = load i32, ptr %1, align 4, !tbaa !5
  call void @bfs(i32 noundef %47)
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  store i32 1, ptr @i, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %65, %44
  %50 = load i32, ptr @i, align 4, !tbaa !5
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %53, label %68

53:                                               ; preds = %49
  %54 = load i32, ptr @i, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [20 x i32], ptr @visited, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %62

59:                                               ; preds = %53
  %60 = load i32, ptr @i, align 4, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %60)
  br label %64

62:                                               ; preds = %53
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %68

64:                                               ; preds = %59
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr @i, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr @i, align 4, !tbaa !5
  br label %49, !llvm.loop !13

68:                                               ; preds = %62, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

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

declare i32 @printf(ptr noundef, ...) #2

declare i32 @__isoc99_scanf(ptr noundef, ...) #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 = { "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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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

@i = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [20 x [20 x i32]], align 16
@visited = external dso_local local_unnamed_addr global [20 x i32], align 16
@q = external dso_local local_unnamed_addr global [20 x i32], align 16
@.str = external hidden unnamed_addr constant [32 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [36 x i8], align 1
@j = external dso_local local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @bfs(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not10 = icmp slt i32 %4, 1
  br i1 %.not10, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %5 = zext nneg i32 %4 to i64
  %6 = shl nuw nsw i64 %5, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @q, i64 4), i8 0, i64 %6, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @visited, i64 4), i8 0, i64 %6, i1 false), !tbaa !5
  %7 = add nuw i32 %4, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %0
  %storemerge.lcssa = phi i32 [ 1, %0 ], [ %7, %.lr.ph.preheader ]
  store i32 %storemerge.lcssa, ptr @i, align 4, !tbaa !5
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  store i32 1, ptr @i, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %.not416 = icmp slt i32 %9, 1
  br i1 %.not416, label %._crit_edge17, label %.preheader

.preheader:                                       ; preds = %._crit_edge, %._crit_edge15
  %10 = phi i32 [ %20, %._crit_edge15 ], [ %9, %._crit_edge ]
  %11 = phi i32 [ %22, %._crit_edge15 ], [ 1, %._crit_edge ]
  store i32 1, ptr @j, align 4, !tbaa !5
  %.not912 = icmp slt i32 %10, 1
  br i1 %.not912, label %._crit_edge15, label %.lr.ph14

.lr.ph14:                                         ; preds = %.preheader, %.lr.ph14
  %storemerge813 = phi i32 [ %18, %.lr.ph14 ], [ 1, %.preheader ]
  %12 = load i32, ptr @i, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = sext i32 %storemerge813 to i64
  %15 = getelementptr inbounds [20 x [20 x i32]], ptr @a, i64 0, i64 %13, i64 %14
  %16 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %15)
  %17 = load i32, ptr @j, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @j, align 4, !tbaa !5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %.not9.not = icmp slt i32 %17, %19
  br i1 %.not9.not, label %.lr.ph14, label %._crit_edge15.loopexit, !llvm.loop !9

._crit_edge15.loopexit:                           ; preds = %.lr.ph14
  %.pre = load i32, ptr @i, align 4, !tbaa !5
  br label %._crit_edge15

._crit_edge15:                                    ; preds = %._crit_edge15.loopexit, %.preheader
  %20 = phi i32 [ %19, %._crit_edge15.loopexit ], [ %10, %.preheader ]
  %21 = phi i32 [ %.pre, %._crit_edge15.loopexit ], [ %11, %.preheader ]
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @i, align 4, !tbaa !5
  %.not4.not = icmp slt i32 %21, %20
  br i1 %.not4.not, label %.preheader, label %._crit_edge17, !llvm.loop !11

._crit_edge17:                                    ; preds = %._crit_edge15, %._crit_edge
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %25 = load i32, ptr %1, align 4, !tbaa !5
  call void @bfs(i32 noundef %25)
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  store i32 1, ptr @i, align 4, !tbaa !5
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %.not618 = icmp slt i32 %27, 1
  br i1 %.not618, label %.loopexit, label %.lr.ph21

.lr.ph21:                                         ; preds = %._crit_edge17, %31
  %storemerge519 = phi i32 [ %34, %31 ], [ 1, %._crit_edge17 ]
  %28 = sext i32 %storemerge519 to i64
  %29 = getelementptr inbounds [20 x i32], ptr @visited, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %.not7 = icmp eq i32 %30, 0
  br i1 %.not7, label %36, label %31

31:                                               ; preds = %.lr.ph21
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %storemerge519)
  %33 = load i32, ptr @i, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @i, align 4, !tbaa !5
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %.not6.not = icmp slt i32 %33, %35
  br i1 %.not6.not, label %.lr.ph21, label %.loopexit, !llvm.loop !13

36:                                               ; preds = %.lr.ph21
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %.loopexit

.loopexit:                                        ; preds = %31, %._crit_edge17, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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.mustprogress"}
!11 = distinct !{!11, !10, !12}
!12 = !{!"llvm.loop.unswitch.partial.disable"}
!13 = distinct !{!13, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass