; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/NUMTSN/B.ll (Z3prev)

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

@dp = external dso_local global [55 x [17 x [17 x [17 x i32]]]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3prev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %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
  store i32 1, ptr @dp, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %114, %0
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 52
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %117

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %110, %15
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 17
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %113

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

21:                                               ; preds = %106, %20
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp slt i32 %22, 17
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %109

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

26:                                               ; preds = %102, %25
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = icmp slt i32 %27, 17
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 11, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %105

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %32
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [17 x [17 x [17 x i32]]], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [17 x [17 x i32]], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [17 x i32], ptr %39, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  store i32 %43, ptr %6, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %47, label %46

46:                                               ; preds = %30
  store i32 13, ptr %2, align 4
  br label %99

47:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %95, %47
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = icmp slt i32 %49, 10
  br i1 %50, label %52, label %51

51:                                               ; preds = %48
  store i32 14, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %98

52:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = icmp eq i32 %54, 3
  %56 = zext i1 %55 to i32
  %57 = add nsw i32 %53, %56
  store i32 %57, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = icmp eq i32 %59, 6
  %61 = zext i1 %60 to i32
  %62 = add nsw i32 %58, %61
  store i32 %62, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = icmp eq i32 %64, 9
  %66 = zext i1 %65 to i32
  %67 = add nsw i32 %63, %66
  store i32 %67, ptr %10, align 4, !tbaa !5
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = icmp sgt i32 %68, 16
  br i1 %69, label %76, label %70

70:                                               ; preds = %52
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = icmp sgt i32 %71, 16
  br i1 %72, label %76, label %73

73:                                               ; preds = %70
  %74 = load i32, ptr %10, align 4, !tbaa !5
  %75 = icmp sgt i32 %74, 16
  br i1 %75, label %76, label %77

76:                                               ; preds = %73, %70, %52
  store i32 16, ptr %2, align 4
  br label %92

77:                                               ; preds = %73
  %78 = load i32, ptr %1, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %80
  %82 = load i32, ptr %8, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [17 x [17 x [17 x i32]]], ptr %81, i64 0, i64 %83
  %85 = load i32, ptr %9, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [17 x [17 x i32]], ptr %84, i64 0, i64 %86
  %88 = load i32, ptr %10, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [17 x i32], ptr %87, i64 0, i64 %89
  %91 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %90, i32 noundef %91)
  store i32 0, ptr %2, align 4
  br label %92

92:                                               ; preds = %77, %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %93 = load i32, ptr %2, align 4
  switch i32 %93, label %118 [
    i32 0, label %94
    i32 16, label %95
  ]

94:                                               ; preds = %92
  br label %95

95:                                               ; preds = %94, %92
  %96 = load i32, ptr %7, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %7, align 4, !tbaa !5
  br label %48, !llvm.loop !9

98:                                               ; preds = %51
  store i32 0, ptr %2, align 4
  br label %99

99:                                               ; preds = %98, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %100 = load i32, ptr %2, align 4
  switch i32 %100, label %118 [
    i32 0, label %101
    i32 13, label %102
  ]

101:                                              ; preds = %99
  br label %102

102:                                              ; preds = %101, %99
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %5, align 4, !tbaa !5
  br label %26, !llvm.loop !11

105:                                              ; preds = %29
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %4, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %4, align 4, !tbaa !5
  br label %21, !llvm.loop !12

109:                                              ; preds = %24
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %3, align 4, !tbaa !5
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %3, align 4, !tbaa !5
  br label %16, !llvm.loop !13

113:                                              ; preds = %19
  br label %114

114:                                              ; preds = %113
  %115 = load i32, ptr %1, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %1, align 4, !tbaa !5
  br label %11, !llvm.loop !14

117:                                              ; preds = %14
  ret void

118:                                              ; preds = %99, %92
  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 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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"

@dp = external dso_local global [55 x [17 x [17 x [17 x i32]]]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3prev() local_unnamed_addr #0 {
  store i32 1, ptr @dp, align 16, !tbaa !5
  br label %.preheader42

.preheader42:                                     ; preds = %0, %4
  %indvars.iv57 = phi i64 [ 0, %0 ], [ %indvars.iv.next58, %4 ]
  %indvars.iv.next58 = add nuw nsw i64 %indvars.iv57, 1
  br label %.preheader41

1:                                                ; preds = %4
  ret void

.preheader41:                                     ; preds = %.preheader42, %7
  %indvars.iv53 = phi i64 [ 0, %.preheader42 ], [ %indvars.iv.next54, %7 ]
  %2 = icmp ugt i64 %indvars.iv53, 15
  %3 = add nuw nsw i64 %indvars.iv53, 1
  br label %.preheader40

4:                                                ; preds = %7
  %exitcond60.not = icmp eq i64 %indvars.iv.next58, 52
  br i1 %exitcond60.not, label %1, label %.preheader42, !llvm.loop !9

.preheader40:                                     ; preds = %.preheader41, %8
  %indvars.iv49 = phi i64 [ 0, %.preheader41 ], [ %indvars.iv.next50, %8 ]
  %5 = icmp ugt i64 %indvars.iv49, 15
  %6 = add nuw nsw i64 %indvars.iv49, 1
  br label %9

7:                                                ; preds = %8
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %exitcond56.not = icmp eq i64 %indvars.iv.next54, 17
  br i1 %exitcond56.not, label %4, label %.preheader41, !llvm.loop !11

8:                                                ; preds = %.loopexit
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next50, 17
  br i1 %exitcond52.not, label %7, label %.preheader40, !llvm.loop !12

9:                                                ; preds = %.preheader40, %.loopexit
  %indvars.iv = phi i64 [ 0, %.preheader40 ], [ %indvars.iv.next.pre-phi, %.loopexit ]
  %10 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv57, i64 %indvars.iv53, i64 %indvars.iv49, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %..loopexit_crit_edge, label %.preheader.3

..loopexit_crit_edge:                             ; preds = %9
  %.pre = add nuw nsw i64 %indvars.iv, 1
  br label %.loopexit

.preheader.3:                                     ; preds = %9
  %12 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %indvars.iv53, i64 %indvars.iv49, i64 %indvars.iv
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %12, i32 noundef %11)
  %13 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %indvars.iv53, i64 %indvars.iv49, i64 %indvars.iv
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %13, i32 noundef %11)
  %14 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %indvars.iv53, i64 %indvars.iv49, i64 %indvars.iv
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %14, i32 noundef %11)
  br i1 %2, label %.preheader.6, label %15

15:                                               ; preds = %.preheader.3
  %16 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %3, i64 %indvars.iv49, i64 %indvars.iv
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %16, i32 noundef %11)
  br label %.preheader.6

.preheader.6:                                     ; preds = %15, %.preheader.3
  %17 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %indvars.iv53, i64 %indvars.iv49, i64 %indvars.iv
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %17, i32 noundef %11)
  %18 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %indvars.iv53, i64 %indvars.iv49, i64 %indvars.iv
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %18, i32 noundef %11)
  br i1 %5, label %.preheader.9, label %19

19:                                               ; preds = %.preheader.6
  %20 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %indvars.iv53, i64 %6, i64 %indvars.iv
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %20, i32 noundef %11)
  br label %.preheader.9

.preheader.9:                                     ; preds = %19, %.preheader.6
  %21 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %indvars.iv53, i64 %indvars.iv49, i64 %indvars.iv
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %21, i32 noundef %11)
  %22 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %indvars.iv53, i64 %indvars.iv49, i64 %indvars.iv
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %22, i32 noundef %11)
  %23 = add nuw nsw i64 %indvars.iv, 1
  %24 = icmp ugt i64 %indvars.iv, 15
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %.preheader.9
  %26 = getelementptr inbounds [55 x [17 x [17 x [17 x i32]]]], ptr @dp, i64 0, i64 %indvars.iv.next58, i64 %indvars.iv53, i64 %indvars.iv49, i64 %23
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %26, i32 noundef %11)
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.9, %25, %..loopexit_crit_edge
  %indvars.iv.next.pre-phi = phi i64 [ %.pre, %..loopexit_crit_edge ], [ %23, %25 ], [ %23, %.preheader.9 ]
  %exitcond.not = icmp eq i64 %indvars.iv.next.pre-phi, 17
  br i1 %exitcond.not, label %8, label %9, !llvm.loop !13
}

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass