; LLVM IR from MinaFaried3/Assiut-University-Training---Newcomers :: l-sheet9_general_medium/K-StarsDrawingEasyEdition.ll (Z10countStarsii)

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

@arr = external dso_local global [1000 x [1000 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: mustprogress uwtable
define dso_local noundef i32 @_Z10countStarsii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %12, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %13 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %13, ptr %11, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %32, %2
  %15 = load i32, ptr %10, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %10, align 4, !tbaa !5
  %17 = icmp ne i32 %15, 0
  br i1 %17, label %18, label %33

18:                                               ; preds = %14
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1000 x [1000 x i8]], ptr @arr, i64 0, i64 %20
  %22 = load i32, ptr %11, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1000 x i8], ptr %21, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %26, 42
  br i1 %27, label %28, label %31

28:                                               ; preds = %18
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !5
  br label %32

31:                                               ; preds = %18
  br label %33

32:                                               ; preds = %28
  br label %14, !llvm.loop !10

33:                                               ; preds = %31, %14
  %34 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %34, ptr %10, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %35, ptr %11, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %54, %33
  %37 = load i32, ptr %10, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %10, align 4, !tbaa !5
  %39 = icmp ne i32 %37, 0
  br i1 %39, label %40, label %55

40:                                               ; preds = %36
  %41 = load i32, ptr %10, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000 x [1000 x i8]], ptr @arr, i64 0, i64 %42
  %44 = load i32, ptr %11, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1000 x i8], ptr %43, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %48, 42
  br i1 %49, label %50, label %53

50:                                               ; preds = %40
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %7, align 4, !tbaa !5
  br label %54

53:                                               ; preds = %40
  br label %55

54:                                               ; preds = %50
  br label %36, !llvm.loop !12

55:                                               ; preds = %53, %36
  %56 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %56, ptr %10, align 4, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %57, ptr %11, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %76, %55
  %59 = load i32, ptr %11, align 4, !tbaa !5
  %60 = add nsw i32 %59, -1
  store i32 %60, ptr %11, align 4, !tbaa !5
  %61 = icmp ne i32 %59, 0
  br i1 %61, label %62, label %77

62:                                               ; preds = %58
  %63 = load i32, ptr %10, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1000 x [1000 x i8]], ptr @arr, i64 0, i64 %64
  %66 = load i32, ptr %11, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [1000 x i8], ptr %65, i64 0, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !9
  %70 = sext i8 %69 to i32
  %71 = icmp eq i32 %70, 42
  br i1 %71, label %72, label %75

72:                                               ; preds = %62
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %8, align 4, !tbaa !5
  br label %76

75:                                               ; preds = %62
  br label %77

76:                                               ; preds = %72
  br label %58, !llvm.loop !13

77:                                               ; preds = %75, %58
  %78 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %78, ptr %10, align 4, !tbaa !5
  %79 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %79, ptr %11, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %98, %77
  %81 = load i32, ptr %11, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %11, align 4, !tbaa !5
  %83 = icmp ne i32 %81, 0
  br i1 %83, label %84, label %99

84:                                               ; preds = %80
  %85 = load i32, ptr %10, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1000 x [1000 x i8]], ptr @arr, i64 0, i64 %86
  %88 = load i32, ptr %11, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [1000 x i8], ptr %87, i64 0, i64 %89
  %91 = load i8, ptr %90, align 1, !tbaa !9
  %92 = sext i8 %91 to i32
  %93 = icmp eq i32 %92, 42
  br i1 %93, label %94, label %97

94:                                               ; preds = %84
  %95 = load i32, ptr %9, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %9, align 4, !tbaa !5
  br label %98

97:                                               ; preds = %84
  br label %99

98:                                               ; preds = %94
  br label %80, !llvm.loop !14

99:                                               ; preds = %97, %80
  %100 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %101 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %100)
  %102 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %101)
  %103 = load i32, ptr %102, align 4, !tbaa !5
  store i32 %103, ptr %5, align 4, !tbaa !5
  %104 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %104
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 #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 = !{!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"

@arr = external dso_local local_unnamed_addr global [1000 x [1000 x i8]], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z10countStarsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %.not26 = icmp eq i32 %0, 0
  br i1 %.not26, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %._crit_edge34

.lr.ph:                                           ; preds = %2
  %7 = sext i32 %1 to i64
  %8 = sext i32 %0 to i64
  br label %9

9:                                                ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ %8, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %10 = phi i32 [ 0, %.lr.ph ], [ %15, %14 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %11 = getelementptr inbounds [1000 x [1000 x i8]], ptr @arr, i64 0, i64 %indvars.iv.next, i64 %7
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = icmp eq i8 %12, 42
  br i1 %13, label %14, label %._crit_edge

14:                                               ; preds = %9
  %15 = add nuw nsw i32 %10, 1
  %.not = icmp eq i64 %indvars.iv.next, 0
  br i1 %.not, label %._crit_edge, label %9, !llvm.loop !10

._crit_edge:                                      ; preds = %14, %9
  %.lcssa = phi i32 [ %0, %14 ], [ %10, %9 ]
  store i32 %.lcssa, ptr %3, align 4, !tbaa !5
  br i1 %.not26, label %._crit_edge34, label %.lr.ph33

.lr.ph33:                                         ; preds = %._crit_edge
  %16 = sext i32 %1 to i64
  %17 = sext i32 %0 to i64
  %18 = sub i32 0, %0
  br label %19

19:                                               ; preds = %.lr.ph33, %24
  %indvars.iv60 = phi i64 [ %17, %.lr.ph33 ], [ %indvars.iv.next61, %24 ]
  %20 = phi i32 [ 0, %.lr.ph33 ], [ %25, %24 ]
  %indvars.iv.next61 = add nsw i64 %indvars.iv60, 1
  %21 = getelementptr inbounds [1000 x [1000 x i8]], ptr @arr, i64 0, i64 %indvars.iv.next61, i64 %16
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = icmp eq i8 %22, 42
  br i1 %23, label %24, label %._crit_edge34

24:                                               ; preds = %19
  %25 = add nuw nsw i32 %20, 1
  %.not23 = icmp eq i64 %indvars.iv.next61, 0
  br i1 %.not23, label %._crit_edge34, label %19, !llvm.loop !12

._crit_edge34:                                    ; preds = %24, %19, %._crit_edge, %._crit_edge.thread
  %.pre-phi = phi i64 [ 0, %._crit_edge.thread ], [ 0, %._crit_edge ], [ %17, %19 ], [ %17, %24 ]
  %.lcssa30 = phi i32 [ 0, %._crit_edge.thread ], [ 0, %._crit_edge ], [ %18, %24 ], [ %20, %19 ]
  store i32 %.lcssa30, ptr %4, align 4, !tbaa !5
  %.not2440 = icmp eq i32 %1, 0
  br i1 %.not2440, label %._crit_edge43.thread, label %.lr.ph42.preheader

._crit_edge43.thread:                             ; preds = %._crit_edge34
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %._crit_edge52

.lr.ph42.preheader:                               ; preds = %._crit_edge34
  %26 = sext i32 %1 to i64
  br label %.lr.ph42

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %31
  %indvars.iv63 = phi i64 [ %26, %.lr.ph42.preheader ], [ %indvars.iv.next64, %31 ]
  %27 = phi i32 [ 0, %.lr.ph42.preheader ], [ %32, %31 ]
  %indvars.iv.next64 = add nsw i64 %indvars.iv63, -1
  %28 = getelementptr inbounds [1000 x [1000 x i8]], ptr @arr, i64 0, i64 %.pre-phi, i64 %indvars.iv.next64
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = icmp eq i8 %29, 42
  br i1 %30, label %31, label %._crit_edge43

31:                                               ; preds = %.lr.ph42
  %32 = add nuw nsw i32 %27, 1
  %.not24 = icmp eq i64 %indvars.iv.next64, 0
  br i1 %.not24, label %._crit_edge43, label %.lr.ph42, !llvm.loop !13

._crit_edge43:                                    ; preds = %31, %.lr.ph42
  %.lcssa39 = phi i32 [ %1, %31 ], [ %27, %.lr.ph42 ]
  store i32 %.lcssa39, ptr %5, align 4, !tbaa !5
  br i1 %.not2440, label %._crit_edge52, label %.lr.ph51.preheader

.lr.ph51.preheader:                               ; preds = %._crit_edge43
  %33 = sext i32 %1 to i64
  %34 = sub i32 0, %1
  br label %.lr.ph51

.lr.ph51:                                         ; preds = %.lr.ph51.preheader, %39
  %indvars.iv66 = phi i64 [ %33, %.lr.ph51.preheader ], [ %indvars.iv.next67, %39 ]
  %35 = phi i32 [ 0, %.lr.ph51.preheader ], [ %40, %39 ]
  %indvars.iv.next67 = add nsw i64 %indvars.iv66, 1
  %36 = getelementptr inbounds [1000 x [1000 x i8]], ptr @arr, i64 0, i64 %.pre-phi, i64 %indvars.iv.next67
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = icmp eq i8 %37, 42
  br i1 %38, label %39, label %._crit_edge52

39:                                               ; preds = %.lr.ph51
  %40 = add nuw nsw i32 %35, 1
  %.not25 = icmp eq i64 %indvars.iv.next67, 0
  br i1 %.not25, label %._crit_edge52, label %.lr.ph51, !llvm.loop !14

._crit_edge52:                                    ; preds = %39, %.lr.ph51, %._crit_edge43.thread, %._crit_edge43
  %.lcssa48 = phi i32 [ 0, %._crit_edge43 ], [ 0, %._crit_edge43.thread ], [ %35, %.lr.ph51 ], [ %34, %39 ]
  store i32 %.lcssa48, ptr %6, align 4, !tbaa !5
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %41)
  %43 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %42)
  %44 = load i32, ptr %43, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i32 %44
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) 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) #0

attributes #0 = { mustprogress 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 = { inlinehint 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 #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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,DSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass