; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/ASC/1/Problem H/H.ll (Z5gaussii)

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

@a = external dso_local global [101 x [101 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5printi(i32 noundef) #0

; 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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5gaussii(i32 noundef %0, i32 noundef %1) #0 {
  %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
  %12 = 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
  br label %13

13:                                               ; preds = %104, %2
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %107

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 -1, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %19 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %19, ptr %9, align 4, !tbaa !5
  br label %20

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

24:                                               ; preds = %20
  store i32 5, ptr %7, align 4
  br label %40

25:                                               ; preds = %20
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %27
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [101 x i32], ptr %28, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %25
  %35 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %35, ptr %8, align 4, !tbaa !5
  store i32 5, ptr %7, align 4
  br label %40

36:                                               ; preds = %25
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %9, align 4, !tbaa !5
  br label %20, !llvm.loop !9

40:                                               ; preds = %34, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = icmp eq i32 %42, -1
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  store i32 4, ptr %7, align 4
  br label %101

45:                                               ; preds = %41
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %47
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %50
  call void @_ZSt4swapIiLm101EENSt9enable_ifIXsr14__is_swappableIT_EE5valueEvE4typeERAT0__S1_S5_(ptr noundef nonnull align 4 dereferenceable(404) %48, ptr noundef nonnull align 4 dereferenceable(404) %51) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %10, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %95, %45
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = icmp slt i32 %55, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %54
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %98

59:                                               ; preds = %54
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %61
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [101 x i32], ptr %62, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %69, label %68

68:                                               ; preds = %59
  br label %95

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

70:                                               ; preds = %91, %69
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = icmp slt i32 %71, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %70
  store i32 11, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %94

75:                                               ; preds = %70
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %77
  %79 = load i32, ptr %11, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [101 x i32], ptr %78, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = load i32, ptr %10, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %84
  %86 = load i32, ptr %11, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [101 x i32], ptr %85, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = xor i32 %89, %82
  store i32 %90, ptr %88, align 4, !tbaa !5
  br label %91

91:                                               ; preds = %75
  %92 = load i32, ptr %11, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %11, align 4, !tbaa !5
  br label %70, !llvm.loop !11

94:                                               ; preds = %74
  br label %95

95:                                               ; preds = %94, %68
  %96 = load i32, ptr %10, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %10, align 4, !tbaa !5
  br label %54, !llvm.loop !12

98:                                               ; preds = %58
  %99 = load i32, ptr %5, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %101

101:                                              ; preds = %98, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %102 = load i32, ptr %7, align 4
  switch i32 %102, label %112 [
    i32 0, label %103
    i32 4, label %104
  ]

103:                                              ; preds = %101
  br label %104

104:                                              ; preds = %103, %101
  %105 = load i32, ptr %6, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %6, align 4, !tbaa !5
  br label %13, !llvm.loop !13

107:                                              ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %108 = load i32, ptr %4, align 4, !tbaa !5
  %109 = load i32, ptr %5, align 4, !tbaa !5
  %110 = sub nsw i32 %108, %109
  store i32 %110, ptr %12, align 4, !tbaa !5
  %111 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z5printi(i32 noundef %111)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void

112:                                              ; preds = %101
  unreachable
}

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

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 = { 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 = 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"

@a = external dso_local global [101 x [101 x i32]], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5gaussii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 0
  br i1 %3, label %.preheader39.us.preheader, label %._crit_edge

.preheader39.us.preheader:                        ; preds = %2
  %wide.trip.count65 = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 4
  %n.vec = and i64 %wide.trip.count65, 2147483644
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count65
  br label %.preheader39.us

.preheader39.us:                                  ; preds = %.preheader39.us.preheader, %.thread.us
  %indvars.iv62 = phi i64 [ 0, %.preheader39.us.preheader ], [ %indvars.iv.next63, %.thread.us ]
  %.049.us = phi i32 [ 0, %.preheader39.us.preheader ], [ %.1.us, %.thread.us ]
  %4 = icmp slt i32 %.049.us, %0
  br i1 %4, label %.lr.ph.us, label %.thread.us

5:                                                ; preds = %.lr.ph.us, %16
  %indvars.iv = phi i64 [ %17, %.lr.ph.us ], [ %indvars.iv.next, %16 ]
  %6 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %indvars.iv, i64 %indvars.iv62
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not.us = icmp eq i32 %7, 0
  br i1 %.not.us, label %16, label %8

8:                                                ; preds = %5
  %9 = icmp eq i64 %indvars.iv, -1
  br i1 %9, label %.thread.us, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %17
  %sext = shl i64 %indvars.iv, 32
  %12 = ashr exact i64 %sext, 32
  %13 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %12
  tail call void @_ZSt4swapIiLm101EENSt9enable_ifIXsr14__is_swappableIT_EE5valueEvE4typeERAT0__S1_S5_(ptr noundef nonnull align 4 dereferenceable(404) %11, ptr noundef nonnull align 4 dereferenceable(404) %13) #2
  %14 = add nsw i32 %.049.us, 1
  %15 = icmp slt i32 %14, %0
  br i1 %15, label %.lr.ph46.us, label %.thread.us

.thread.us:                                       ; preds = %16, %..loopexit_crit_edge.us.us, %.preheader39.us, %10, %8
  %.1.us = phi i32 [ %.049.us, %8 ], [ %14, %10 ], [ %.049.us, %.preheader39.us ], [ %14, %..loopexit_crit_edge.us.us ], [ %.049.us, %16 ]
  %indvars.iv.next63 = add nuw nsw i64 %indvars.iv62, 1
  %exitcond66.not = icmp eq i64 %indvars.iv.next63, %wide.trip.count65
  br i1 %exitcond66.not, label %._crit_edge, label %.preheader39.us, !llvm.loop !9

16:                                               ; preds = %5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %lftr.wideiv, %0
  br i1 %exitcond.not, label %.thread.us, label %5, !llvm.loop !11

.lr.ph.us:                                        ; preds = %.preheader39.us
  %17 = sext i32 %.049.us to i64
  br label %5

.lr.ph46.us:                                      ; preds = %10
  %18 = add nsw i64 %17, 1
  br label %19

19:                                               ; preds = %..loopexit_crit_edge.us.us, %.lr.ph46.us
  %indvars.iv57 = phi i64 [ %indvars.iv.next58, %..loopexit_crit_edge.us.us ], [ %18, %.lr.ph46.us ]
  %20 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %indvars.iv57, i64 %indvars.iv62
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not37.us.us = icmp eq i32 %21, 0
  br i1 %.not37.us.us, label %..loopexit_crit_edge.us.us, label %.preheader.us.us.preheader

.preheader.us.us.preheader:                       ; preds = %19
  br i1 %min.iters.check, label %.preheader.us.us.preheader72, label %vector.body

vector.body:                                      ; preds = %.preheader.us.us.preheader, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us.us.preheader ]
  %22 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %17, i64 %index
  %wide.load = load <4 x i32>, ptr %22, align 4, !tbaa !5
  %23 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %indvars.iv57, i64 %index
  %wide.load71 = load <4 x i32>, ptr %23, align 4, !tbaa !5
  %24 = xor <4 x i32> %wide.load71, %wide.load
  store <4 x i32> %24, ptr %23, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %..loopexit_crit_edge.us.us, label %.preheader.us.us.preheader72

.preheader.us.us.preheader72:                     ; preds = %middle.block, %.preheader.us.us.preheader
  %indvars.iv53.ph = phi i64 [ 0, %.preheader.us.us.preheader ], [ %n.vec, %middle.block ]
  br label %.preheader.us.us

.preheader.us.us:                                 ; preds = %.preheader.us.us.preheader72, %.preheader.us.us
  %indvars.iv53 = phi i64 [ %indvars.iv.next54, %.preheader.us.us ], [ %indvars.iv53.ph, %.preheader.us.us.preheader72 ]
  %26 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %17, i64 %indvars.iv53
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = getelementptr inbounds [101 x [101 x i32]], ptr @a, i64 0, i64 %indvars.iv57, i64 %indvars.iv53
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = xor i32 %29, %27
  store i32 %30, ptr %28, align 4, !tbaa !5
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %exitcond56.not = icmp eq i64 %indvars.iv.next54, %wide.trip.count65
  br i1 %exitcond56.not, label %..loopexit_crit_edge.us.us, label %.preheader.us.us, !llvm.loop !15

..loopexit_crit_edge.us.us:                       ; preds = %.preheader.us.us, %middle.block, %19
  %indvars.iv.next58 = add nsw i64 %indvars.iv57, 1
  %lftr.wideiv60 = trunc i64 %indvars.iv.next58 to i32
  %exitcond61.not = icmp eq i32 %lftr.wideiv60, %0
  br i1 %exitcond61.not, label %.thread.us, label %19, !llvm.loop !16

._crit_edge:                                      ; preds = %.thread.us, %2
  %.0.lcssa = phi i32 [ 0, %2 ], [ %.1.us, %.thread.us ]
  %31 = sub nsw i32 %1, %.0.lcssa
  tail call void @_Z5printi(i32 noundef %31)
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiLm101EENSt9enable_ifIXsr14__is_swappableIT_EE5valueEvE4typeERAT0__S1_S5_(ptr noundef nonnull align 4 dereferenceable(404), ptr noundef nonnull align 4 dereferenceable(404)) local_unnamed_addr #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 = { 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 #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, !14}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !10, !14, !13}
!16 = distinct !{!16, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass