; LLVM IR from ahampriyanshu/algo-ds-101 :: Algorithms/Matrix/Spiral-Matrix (Spiral-Matrix)

; 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z20spirallyDFSTravsersePA4_iiiiRSt6vectorIiSaIiEE(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 8 dereferenceable(24) %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %17, i32 noundef %18, i32 noundef %19)
  br i1 %20, label %21, label %22

21:                                               ; preds = %5
  br label %147

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

23:                                               ; preds = %47, %22
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = icmp sle i32 %24, 1
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %50

27:                                               ; preds = %23
  %28 = load i8, ptr %11, align 1, !tbaa !11, !range !13, !noundef !14
  %29 = trunc i8 %28 to i1
  br i1 %29, label %30, label %44

30:                                               ; preds = %27
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = add nsw i32 %32, %33
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %31, i32 noundef %34, i32 noundef %35)
  br i1 %36, label %37, label %44

37:                                               ; preds = %30
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = add nsw i32 %40, %41
  %43 = call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %38, i32 noundef %39, i32 noundef %42)
  br label %44

44:                                               ; preds = %37, %30, %27
  %45 = phi i1 [ false, %30 ], [ false, %27 ], [ %43, %37 ]
  %46 = zext i1 %45 to i8
  store i8 %46, ptr %11, align 1, !tbaa !11
  br label %47

47:                                               ; preds = %44
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = add nsw i32 %48, 2
  store i32 %49, ptr %12, align 4, !tbaa !9
  br label %23, !llvm.loop !15

50:                                               ; preds = %26
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [4 x i32], ptr %52, i64 %54
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [4 x i32], ptr %55, i64 0, i64 %57
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %51, ptr noundef nonnull align 4 dereferenceable(4) %58)
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [4 x i32], ptr %59, i64 %61
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [4 x i32], ptr %62, i64 0, i64 %64
  store i32 -1, ptr %65, align 4, !tbaa !9
  %66 = load i8, ptr %11, align 1, !tbaa !11, !range !13, !noundef !14
  %67 = trunc i8 %66 to i1
  br i1 %67, label %68, label %69

68:                                               ; preds = %50
  store i32 1, ptr %13, align 4
  br label %145

69:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %70 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %70, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %71 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %71, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %72 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %72, ptr %16, align 4, !tbaa !9
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %88

75:                                               ; preds = %69
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  %80 = call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %76, i32 noundef %77, i32 noundef %79)
  br i1 %80, label %84, label %81

81:                                               ; preds = %75
  %82 = load i32, ptr %15, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %15, align 4, !tbaa !9
  br label %87

84:                                               ; preds = %75
  store i32 1, ptr %16, align 4, !tbaa !9
  %85 = load i32, ptr %14, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %14, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %84, %81
  br label %139

88:                                               ; preds = %69
  %89 = load i32, ptr %9, align 4, !tbaa !9
  %90 = icmp eq i32 %89, 1
  br i1 %90, label %91, label %104

91:                                               ; preds = %88
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = load i32, ptr %7, align 4, !tbaa !9
  %94 = add nsw i32 %93, 1
  %95 = load i32, ptr %8, align 4, !tbaa !9
  %96 = call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %92, i32 noundef %94, i32 noundef %95)
  br i1 %96, label %100, label %97

97:                                               ; preds = %91
  %98 = load i32, ptr %14, align 4, !tbaa !9
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %14, align 4, !tbaa !9
  br label %103

100:                                              ; preds = %91
  store i32 2, ptr %16, align 4, !tbaa !9
  %101 = load i32, ptr %15, align 4, !tbaa !9
  %102 = add nsw i32 %101, -1
  store i32 %102, ptr %15, align 4, !tbaa !9
  br label %103

103:                                              ; preds = %100, %97
  br label %138

104:                                              ; preds = %88
  %105 = load i32, ptr %9, align 4, !tbaa !9
  %106 = icmp eq i32 %105, 2
  br i1 %106, label %107, label %120

107:                                              ; preds = %104
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = load i32, ptr %7, align 4, !tbaa !9
  %110 = load i32, ptr %8, align 4, !tbaa !9
  %111 = sub nsw i32 %110, 1
  %112 = call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %108, i32 noundef %109, i32 noundef %111)
  br i1 %112, label %116, label %113

113:                                              ; preds = %107
  %114 = load i32, ptr %15, align 4, !tbaa !9
  %115 = add nsw i32 %114, -1
  store i32 %115, ptr %15, align 4, !tbaa !9
  br label %119

116:                                              ; preds = %107
  store i32 3, ptr %16, align 4, !tbaa !9
  %117 = load i32, ptr %14, align 4, !tbaa !9
  %118 = add nsw i32 %117, -1
  store i32 %118, ptr %14, align 4, !tbaa !9
  br label %119

119:                                              ; preds = %116, %113
  br label %137

120:                                              ; preds = %104
  %121 = load i32, ptr %9, align 4, !tbaa !9
  %122 = icmp eq i32 %121, 3
  br i1 %122, label %123, label %136

123:                                              ; preds = %120
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = load i32, ptr %7, align 4, !tbaa !9
  %126 = sub nsw i32 %125, 1
  %127 = load i32, ptr %8, align 4, !tbaa !9
  %128 = call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %124, i32 noundef %126, i32 noundef %127)
  br i1 %128, label %132, label %129

129:                                              ; preds = %123
  %130 = load i32, ptr %14, align 4, !tbaa !9
  %131 = add nsw i32 %130, -1
  store i32 %131, ptr %14, align 4, !tbaa !9
  br label %135

132:                                              ; preds = %123
  store i32 0, ptr %16, align 4, !tbaa !9
  %133 = load i32, ptr %15, align 4, !tbaa !9
  %134 = add nsw i32 %133, 1
  store i32 %134, ptr %15, align 4, !tbaa !9
  br label %135

135:                                              ; preds = %132, %129
  br label %136

136:                                              ; preds = %135, %120
  br label %137

137:                                              ; preds = %136, %119
  br label %138

138:                                              ; preds = %137, %103
  br label %139

139:                                              ; preds = %138, %87
  %140 = load ptr, ptr %6, align 8, !tbaa !5
  %141 = load i32, ptr %14, align 4, !tbaa !9
  %142 = load i32, ptr %15, align 4, !tbaa !9
  %143 = load i32, ptr %16, align 4, !tbaa !9
  %144 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_Z20spirallyDFSTravsersePA4_iiiiRSt6vectorIiSaIiEE(ptr noundef %140, i32 noundef %141, i32 noundef %142, i32 noundef %143, ptr noundef nonnull align 8 dereferenceable(24) %144)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  store i32 0, ptr %13, align 4
  br label %145

145:                                              ; preds = %139, %68
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  %146 = load i32, ptr %13, align 4
  switch i32 %146, label %148 [
    i32 0, label %147
    i32 1, label %147
  ]

147:                                              ; preds = %145, %145, %21
  ret void

148:                                              ; preds = %145
  unreachable
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

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


; 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z20spirallyDFSTravsersePA4_iiiiRSt6vectorIiSaIiEE(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 8 dereferenceable(24) %4) local_unnamed_addr #1 {
  %6 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %0, i32 noundef %1, i32 noundef %2)
  br i1 %6, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %5, %tailrecurse
  %.tr6066 = phi i32 [ %.0, %tailrecurse ], [ %3, %5 ]
  %.tr5965 = phi i32 [ %.053, %tailrecurse ], [ %2, %5 ]
  %.tr5864 = phi i32 [ %.054, %tailrecurse ], [ %1, %5 ]
  %7 = add nsw i32 %.tr5864, -1
  %8 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %0, i32 noundef %7, i32 noundef %.tr5965)
  br i1 %8, label %9, label %.critedge

9:                                                ; preds = %.preheader.preheader
  %10 = add nsw i32 %.tr5965, -1
  %11 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %0, i32 noundef %.tr5864, i32 noundef %10)
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %9
  %13 = add nsw i32 %.tr5864, 1
  %14 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %0, i32 noundef %13, i32 noundef %.tr5965)
  br i1 %14, label %.thread, label %.critedge

.thread:                                          ; preds = %12
  %15 = add nsw i32 %.tr5965, 1
  %16 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef %0, i32 noundef %.tr5864, i32 noundef %15)
  %17 = sext i32 %.tr5864 to i64
  %18 = sext i32 %.tr5965 to i64
  %19 = getelementptr inbounds [4 x i32], ptr %0, i64 %17, i64 %18
  tail call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 4 dereferenceable(4) %19)
  store i32 -1, ptr %19, align 4, !tbaa !5
  br i1 %16, label %._crit_edge, label %23

.critedge:                                        ; preds = %.preheader.preheader, %9, %12
  %20 = sext i32 %.tr5864 to i64
  %21 = sext i32 %.tr5965 to i64
  %22 = getelementptr inbounds [4 x i32], ptr %0, i64 %20, i64 %21
  tail call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 4 dereferenceable(4) %22)
  store i32 -1, ptr %22, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %.critedge, %.thread
  switch i32 %.tr6066, label %tailrecurse [
    i32 0, label %24
    i32 1, label %29
    i32 2, label %34
    i32 3, label %39
  ]

24:                                               ; preds = %23
  %25 = add nsw i32 %.tr5965, 1
  %26 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef nonnull %0, i32 noundef %.tr5864, i32 noundef %25)
  br i1 %26, label %27, label %tailrecurse

27:                                               ; preds = %24
  %28 = add nsw i32 %.tr5864, 1
  br label %tailrecurse

29:                                               ; preds = %23
  %30 = add nsw i32 %.tr5864, 1
  %31 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef nonnull %0, i32 noundef %30, i32 noundef %.tr5965)
  br i1 %31, label %32, label %tailrecurse

32:                                               ; preds = %29
  %33 = add nsw i32 %.tr5965, -1
  br label %tailrecurse

34:                                               ; preds = %23
  %35 = add nsw i32 %.tr5965, -1
  %36 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef nonnull %0, i32 noundef %.tr5864, i32 noundef %35)
  br i1 %36, label %37, label %tailrecurse

37:                                               ; preds = %34
  %38 = add nsw i32 %.tr5864, -1
  br label %tailrecurse

39:                                               ; preds = %23
  %40 = add nsw i32 %.tr5864, -1
  %41 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef nonnull %0, i32 noundef %40, i32 noundef %.tr5965)
  br i1 %41, label %42, label %tailrecurse

42:                                               ; preds = %39
  %43 = add nsw i32 %.tr5965, 1
  br label %tailrecurse

tailrecurse:                                      ; preds = %39, %34, %23, %29, %24, %32, %42, %37, %27
  %.054 = phi i32 [ %28, %27 ], [ %.tr5864, %32 ], [ %38, %37 ], [ %.tr5864, %42 ], [ %.tr5864, %24 ], [ %30, %29 ], [ %.tr5864, %23 ], [ %.tr5864, %34 ], [ %40, %39 ]
  %.053 = phi i32 [ %.tr5965, %27 ], [ %33, %32 ], [ %.tr5965, %37 ], [ %43, %42 ], [ %25, %24 ], [ %.tr5965, %29 ], [ %.tr5965, %23 ], [ %35, %34 ], [ %.tr5965, %39 ]
  %.0 = phi i32 [ 1, %27 ], [ 2, %32 ], [ 3, %37 ], [ 0, %42 ], [ 0, %24 ], [ 1, %29 ], [ %.tr6066, %23 ], [ 2, %34 ], [ 3, %39 ]
  %44 = tail call noundef zeroext i1 @_Z9isBlockedPA4_iii(ptr noundef nonnull %0, i32 noundef %.054, i32 noundef %.053)
  br i1 %44, label %._crit_edge, label %.preheader.preheader

._crit_edge:                                      ; preds = %tailrecurse, %.thread, %5
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

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

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


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