; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/Educational 14/Problem E/E.ll (Z4fastx)

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

@m = external dso_local global [110 x [110 x i64]], align 16
@ret = external dso_local global [110 x [110 x i64]], align 16
@n = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3mulPA110_xS0_(ptr noundef, ptr 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 nounwind uwtable
define dso_local void @_Z4fastx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %20, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = load i64, ptr @n, align 8, !tbaa !5
  %11 = icmp sle i64 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %7
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [110 x [110 x i64]], ptr @ret, i64 0, i64 %15
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [110 x i64], ptr %16, i64 0, i64 %18
  store i64 1, ptr %19, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %13
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !11

23:                                               ; preds = %12
  br label %24

24:                                               ; preds = %32, %23
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = icmp sgt i64 %25, 0
  br i1 %26, label %27, label %35

27:                                               ; preds = %24
  %28 = load i64, ptr %2, align 8, !tbaa !5
  %29 = srem i64 %28, 2
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  call void @_Z3mulPA110_xS0_(ptr noundef @ret, ptr noundef @m)
  br label %32

32:                                               ; preds = %31, %27
  call void @_Z3mulPA110_xS0_(ptr noundef @m, ptr noundef @m)
  %33 = load i64, ptr %2, align 8, !tbaa !5
  %34 = ashr i64 %33, 1
  store i64 %34, ptr %2, align 8, !tbaa !5
  br label %24, !llvm.loop !13

35:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %67, %35
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = load i64, ptr @n, align 8, !tbaa !5
  %40 = icmp sle i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  store i32 7, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %70

42:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %63, %42
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = load i64, ptr @n, align 8, !tbaa !5
  %47 = icmp sle i64 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %43
  store i32 10, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %66

49:                                               ; preds = %43
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [110 x [110 x i64]], ptr @ret, i64 0, i64 %51
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [110 x i64], ptr %52, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [110 x [110 x i64]], ptr @m, i64 0, i64 %58
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [110 x i64], ptr %59, i64 0, i64 %61
  store i64 %56, ptr %62, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %49
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %6, align 4, !tbaa !9
  br label %43, !llvm.loop !14

66:                                               ; preds = %48
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %4, align 4, !tbaa !9
  br label %36, !llvm.loop !15

70:                                               ; preds = %41
  ret void
}

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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

@m = external dso_local global [110 x [110 x i64]], align 16
@ret = external dso_local global [110 x [110 x i64]], align 16
@n = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3mulPA110_xS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4fastx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %.not26 = icmp slt i64 %2, 1
  br i1 %.not26, label %.preheader25, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %xtraiter = and i64 %2, 3
  %3 = icmp ult i64 %2, 4
  br i1 %3, label %.preheader25.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %2, 9223372036854775804
  br label %.lr.ph

.preheader25.loopexit.unr-lcssa:                  ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader25, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader25.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.preheader25.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader25.loopexit.unr-lcssa ]
  %4 = getelementptr inbounds [110 x [110 x i64]], ptr @ret, i64 0, i64 %indvars.iv.epil, i64 %indvars.iv.epil
  store i64 1, ptr %4, align 8, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader25, label %.lr.ph.epil, !llvm.loop !9

.preheader25:                                     ; preds = %.preheader25.loopexit.unr-lcssa, %.lr.ph.epil, %1
  %5 = icmp sgt i64 %0, 0
  br i1 %5, label %.lr.ph29, label %.preheader24

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %6 = getelementptr inbounds [110 x [110 x i64]], ptr @ret, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i64 1, ptr %6, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = getelementptr inbounds [110 x [110 x i64]], ptr @ret, i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next
  store i64 1, ptr %7, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %8 = getelementptr inbounds [110 x [110 x i64]], ptr @ret, i64 0, i64 %indvars.iv.next.1, i64 %indvars.iv.next.1
  store i64 1, ptr %8, align 8, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %9 = getelementptr inbounds [110 x [110 x i64]], ptr @ret, i64 0, i64 %indvars.iv.next.2, i64 %indvars.iv.next.2
  store i64 1, ptr %9, align 8, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader25.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11

.preheader24.loopexit:                            ; preds = %15
  %.pre = load i64, ptr @n, align 8, !tbaa !5
  br label %.preheader24

.preheader24:                                     ; preds = %.preheader24.loopexit, %.preheader25
  %10 = phi i64 [ %.pre, %.preheader24.loopexit ], [ %2, %.preheader25 ]
  %.not2133 = icmp slt i64 %10, 1
  br i1 %.not2133, label %._crit_edge35, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader24
  %11 = shl nuw i64 %10, 3
  %xtraiter46 = and i64 %10, 1
  %12 = icmp eq i64 %10, 1
  br i1 %12, label %._crit_edge35.loopexit.unr-lcssa, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.preheader
  %unroll_iter49 = and i64 %10, 9223372036854775806
  br label %.preheader

.lr.ph29:                                         ; preds = %.preheader25, %15
  %.01728 = phi i64 [ %16, %15 ], [ %0, %.preheader25 ]
  %13 = and i64 %.01728, 1
  %.not23 = icmp eq i64 %13, 0
  br i1 %.not23, label %15, label %14

14:                                               ; preds = %.lr.ph29
  tail call void @_Z3mulPA110_xS0_(ptr noundef nonnull @ret, ptr noundef nonnull @m)
  br label %15

15:                                               ; preds = %14, %.lr.ph29
  tail call void @_Z3mulPA110_xS0_(ptr noundef nonnull @m, ptr noundef nonnull @m)
  %16 = lshr i64 %.01728, 1
  %.not36 = icmp ult i64 %.01728, 2
  br i1 %.not36, label %.preheader24.loopexit, label %.lr.ph29, !llvm.loop !13

.preheader:                                       ; preds = %.preheader, %.preheader.preheader.new
  %indvar = phi i64 [ 0, %.preheader.preheader.new ], [ %indvar.next.1, %.preheader ]
  %niter50 = phi i64 [ 0, %.preheader.preheader.new ], [ %niter50.next.1, %.preheader ]
  %17 = mul nuw i64 %indvar, 880
  %18 = add nuw i64 %17, 888
  %scevgep = getelementptr i8, ptr @m, i64 %18
  %scevgep38 = getelementptr i8, ptr @ret, i64 %18
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %scevgep, ptr align 8 %scevgep38, i64 %11, i1 false), !tbaa !5
  %19 = mul nuw i64 %indvar, 880
  %20 = add nuw i64 %19, 1768
  %scevgep.1 = getelementptr i8, ptr @m, i64 %20
  %scevgep38.1 = getelementptr i8, ptr @ret, i64 %20
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %scevgep.1, ptr align 8 %scevgep38.1, i64 %11, i1 false), !tbaa !5
  %indvar.next.1 = add nuw nsw i64 %indvar, 2
  %niter50.next.1 = add i64 %niter50, 2
  %niter50.ncmp.1 = icmp eq i64 %niter50.next.1, %unroll_iter49
  br i1 %niter50.ncmp.1, label %._crit_edge35.loopexit.unr-lcssa.loopexit, label %.preheader, !llvm.loop !14

._crit_edge35.loopexit.unr-lcssa.loopexit:        ; preds = %.preheader
  %21 = mul nuw i64 %indvar.next.1, 880
  %22 = add nuw i64 %21, 888
  br label %._crit_edge35.loopexit.unr-lcssa

._crit_edge35.loopexit.unr-lcssa:                 ; preds = %._crit_edge35.loopexit.unr-lcssa.loopexit, %.preheader.preheader
  %indvar.unr = phi i64 [ 888, %.preheader.preheader ], [ %22, %._crit_edge35.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod48.not = icmp eq i64 %xtraiter46, 0
  br i1 %lcmp.mod48.not, label %._crit_edge35, label %.preheader.epil

.preheader.epil:                                  ; preds = %._crit_edge35.loopexit.unr-lcssa
  %scevgep.epil = getelementptr i8, ptr @m, i64 %indvar.unr
  %scevgep38.epil = getelementptr i8, ptr @ret, i64 %indvar.unr
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %scevgep.epil, ptr align 8 %scevgep38.epil, i64 %11, i1 false), !tbaa !5
  br label %._crit_edge35

._crit_edge35:                                    ; preds = %.preheader.epil, %._crit_edge35.loopexit.unr-lcssa, %.preheader24
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 nounwind willreturn memory(argmem: readwrite) }

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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