; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/341 Division 2/Problem E/E.ll (Z4mul1v)

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

@x = external dso_local global i32, align 4
@m = external dso_local global [100 x [100 x i64]], align 16
@id = external dso_local global [100 x [100 x i64]], align 16
@tmp = external dso_local global [100 x [100 x i64]], align 16
@MOD = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4mul1v() #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
  call void @llvm.memset.p0.i64(ptr align 16 @tmp, i8 0, i64 80000, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %78, %0
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = load i32, ptr @x, align 4, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %12, label %11

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

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

13:                                               ; preds = %74, %12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr @x, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

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

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

19:                                               ; preds = %70, %18
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr @x, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %19
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %26
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100 x i64], ptr %27, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100 x [100 x i64]], ptr @m, i64 0, i64 %33
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100 x i64], ptr %34, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = mul nsw i64 %31, %38
  %40 = load i64, ptr @MOD, align 8, !tbaa !9
  %41 = srem i64 %39, %40
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100 x [100 x i64]], ptr @tmp, i64 0, i64 %43
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100 x i64], ptr %44, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = add nsw i64 %48, %41
  store i64 %49, ptr %47, align 8, !tbaa !9
  %50 = load i32, ptr %1, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100 x [100 x i64]], ptr @tmp, i64 0, i64 %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100 x i64], ptr %52, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !9
  %57 = load i64, ptr @MOD, align 8, !tbaa !9
  %58 = icmp sge i64 %56, %57
  br i1 %58, label %59, label %69

59:                                               ; preds = %24
  %60 = load i64, ptr @MOD, align 8, !tbaa !9
  %61 = load i32, ptr %1, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100 x [100 x i64]], ptr @tmp, i64 0, i64 %62
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100 x i64], ptr %63, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !9
  %68 = sub nsw i64 %67, %60
  store i64 %68, ptr %66, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %59, %24
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %4, align 4, !tbaa !5
  br label %19, !llvm.loop !11

73:                                               ; preds = %23
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !13

77:                                               ; preds = %17
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %1, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %1, align 4, !tbaa !5
  br label %7, !llvm.loop !14

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

82:                                               ; preds = %111, %81
  %83 = load i32, ptr %5, align 4, !tbaa !5
  %84 = load i32, ptr @x, align 4, !tbaa !5
  %85 = icmp slt i32 %83, %84
  br i1 %85, label %87, label %86

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

87:                                               ; preds = %82
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %107, %87
  %89 = load i32, ptr %6, align 4, !tbaa !5
  %90 = load i32, ptr @x, align 4, !tbaa !5
  %91 = icmp slt i32 %89, %90
  br i1 %91, label %93, label %92

92:                                               ; preds = %88
  store i32 14, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %110

93:                                               ; preds = %88
  %94 = load i32, ptr %5, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [100 x [100 x i64]], ptr @tmp, i64 0, i64 %95
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [100 x i64], ptr %96, i64 0, i64 %98
  %100 = load i64, ptr %99, align 8, !tbaa !9
  %101 = load i32, ptr %5, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %102
  %104 = load i32, ptr %6, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [100 x i64], ptr %103, i64 0, i64 %105
  store i64 %100, ptr %106, align 8, !tbaa !9
  br label %107

107:                                              ; preds = %93
  %108 = load i32, ptr %6, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %6, align 4, !tbaa !5
  br label %88, !llvm.loop !15

110:                                              ; preds = %92
  br label %111

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

114:                                              ; preds = %86
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; 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

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

@x = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global [100 x [100 x i64]], align 16
@id = external dso_local local_unnamed_addr global [100 x [100 x i64]], align 16
@tmp = external dso_local local_unnamed_addr global [100 x [100 x i64]], align 16
@MOD = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4mul1v() local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(80000) @tmp, i8 0, i64 80000, i1 false)
  %1 = load i32, ptr @x, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.preheader32.lr.ph, label %._crit_edge40

.preheader32.lr.ph:                               ; preds = %0
  %3 = load i64, ptr @MOD, align 8
  %wide.trip.count50 = zext nneg i32 %1 to i64
  br label %.preheader32.us

.preheader32.us:                                  ; preds = %._crit_edge36.split.us.us, %.preheader32.lr.ph
  %indvars.iv47 = phi i64 [ %indvars.iv.next48, %._crit_edge36.split.us.us ], [ 0, %.preheader32.lr.ph ]
  br label %.preheader31.us.us

.preheader31.us.us:                               ; preds = %._crit_edge.us.us, %.preheader32.us
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %._crit_edge.us.us ], [ 0, %.preheader32.us ]
  %4 = getelementptr inbounds [100 x [100 x i64]], ptr @tmp, i64 0, i64 %indvars.iv47, i64 %indvars.iv42
  %.promoted.us.us = load i64, ptr %4, align 8, !tbaa !9
  br label %5

5:                                                ; preds = %5, %.preheader31.us.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %5 ], [ 0, %.preheader31.us.us ]
  %spec.select34.us.us = phi i64 [ %spec.select.us.us, %5 ], [ %.promoted.us.us, %.preheader31.us.us ]
  %6 = getelementptr inbounds [100 x [100 x i64]], ptr @id, i64 0, i64 %indvars.iv47, i64 %indvars.iv
  %7 = load i64, ptr %6, align 8, !tbaa !9
  %8 = getelementptr inbounds [100 x [100 x i64]], ptr @m, i64 0, i64 %indvars.iv, i64 %indvars.iv42
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = mul nsw i64 %9, %7
  %11 = srem i64 %10, %3
  %12 = add nsw i64 %spec.select34.us.us, %11
  %.not.us.us = icmp slt i64 %12, %3
  %13 = select i1 %.not.us.us, i64 0, i64 %3
  %spec.select.us.us = sub nsw i64 %12, %13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count50
  br i1 %exitcond.not, label %._crit_edge.us.us, label %5, !llvm.loop !11

._crit_edge.us.us:                                ; preds = %5
  store i64 %spec.select.us.us, ptr %4, align 8, !tbaa !9
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next43, %wide.trip.count50
  br i1 %exitcond46.not, label %._crit_edge36.split.us.us, label %.preheader31.us.us, !llvm.loop !13

._crit_edge36.split.us.us:                        ; preds = %._crit_edge.us.us
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %exitcond51.not = icmp eq i64 %indvars.iv.next48, %wide.trip.count50
  br i1 %exitcond51.not, label %.preheader30, label %.preheader32.us, !llvm.loop !14

.preheader30:                                     ; preds = %._crit_edge36.split.us.us
  br i1 %2, label %.preheader.us.preheader, label %._crit_edge40

.preheader.us.preheader:                          ; preds = %.preheader30
  %14 = zext nneg i32 %1 to i64
  %15 = shl nuw nsw i64 %14, 3
  %xtraiter = and i64 %wide.trip.count50, 3
  %16 = icmp ult i32 %1, 4
  br i1 %16, label %._crit_edge40.loopexit.unr-lcssa, label %.preheader.us.preheader.new

.preheader.us.preheader.new:                      ; preds = %.preheader.us.preheader
  %unroll_iter = and i64 %wide.trip.count50, 2147483644
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us, %.preheader.us.preheader.new
  %indvar = phi i64 [ 0, %.preheader.us.preheader.new ], [ %indvar.next.3, %.preheader.us ]
  %niter = phi i64 [ 0, %.preheader.us.preheader.new ], [ %niter.next.3, %.preheader.us ]
  %17 = mul nuw nsw i64 %indvar, 800
  %scevgep = getelementptr i8, ptr @id, i64 %17
  %scevgep52 = getelementptr i8, ptr @tmp, i64 %17
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep, ptr align 16 %scevgep52, i64 %15, i1 false), !tbaa !9
  %18 = mul nuw i64 %indvar, 800
  %19 = add nuw i64 %18, 800
  %scevgep.1 = getelementptr i8, ptr @id, i64 %19
  %scevgep52.1 = getelementptr i8, ptr @tmp, i64 %19
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.1, ptr align 16 %scevgep52.1, i64 %15, i1 false), !tbaa !9
  %20 = mul nuw i64 %indvar, 800
  %21 = add nuw i64 %20, 1600
  %scevgep.2 = getelementptr i8, ptr @id, i64 %21
  %scevgep52.2 = getelementptr i8, ptr @tmp, i64 %21
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.2, ptr align 16 %scevgep52.2, i64 %15, i1 false), !tbaa !9
  %22 = mul nuw i64 %indvar, 800
  %23 = add nuw i64 %22, 2400
  %scevgep.3 = getelementptr i8, ptr @id, i64 %23
  %scevgep52.3 = getelementptr i8, ptr @tmp, i64 %23
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.3, ptr align 16 %scevgep52.3, i64 %15, i1 false), !tbaa !9
  %indvar.next.3 = add nuw nsw i64 %indvar, 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 %._crit_edge40.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !15

._crit_edge40.loopexit.unr-lcssa:                 ; preds = %.preheader.us, %.preheader.us.preheader
  %indvar.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %indvar.next.3, %.preheader.us ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge40, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge40.loopexit.unr-lcssa, %.preheader.us.epil
  %indvar.epil = phi i64 [ %indvar.next.epil, %.preheader.us.epil ], [ %indvar.unr, %._crit_edge40.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.us.epil ], [ 0, %._crit_edge40.loopexit.unr-lcssa ]
  %24 = mul nuw nsw i64 %indvar.epil, 800
  %scevgep.epil = getelementptr i8, ptr @id, i64 %24
  %scevgep52.epil = getelementptr i8, ptr @tmp, i64 %24
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.epil, ptr align 16 %scevgep52.epil, i64 %15, i1 false), !tbaa !9
  %indvar.next.epil = add nuw nsw i64 %indvar.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 %._crit_edge40, label %.preheader.us.epil, !llvm.loop !16

._crit_edge40:                                    ; preds = %._crit_edge40.loopexit.unr-lcssa, %.preheader.us.epil, %0, %.preheader30
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; 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) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}


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