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

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

@res = external dso_local global [32 x [32 x i32]], align 16
@n = external dso_local global i32, align 4
@p = external dso_local global i32, align 4

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

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

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

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

11:                                               ; preds = %68, %2
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = load i32, ptr @n, align 4, !tbaa !9
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

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

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

17:                                               ; preds = %64, %16
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load i32, ptr @n, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %17
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [32 x [32 x i32]], ptr @res, i64 0, i64 %24
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [32 x i32], ptr %25, i64 0, i64 %27
  store i32 0, ptr %28, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %60, %22
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load i32, ptr @n, align 4, !tbaa !9
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %63

34:                                               ; preds = %29
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [32 x [32 x i32]], ptr @res, i64 0, i64 %36
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [32 x i32], ptr %37, i64 0, i64 %39
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [32 x i32], ptr %41, i64 %43
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [32 x i32], ptr %44, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [32 x i32], ptr %49, i64 %51
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [32 x i32], ptr %52, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = mul nsw i32 %48, %56
  %58 = load i32, ptr @p, align 4, !tbaa !9
  %59 = srem i32 %57, %58
  call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %40, i32 noundef %59)
  br label %60

60:                                               ; preds = %34
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %8, align 4, !tbaa !9
  br label %29, !llvm.loop !11

63:                                               ; preds = %33
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %7, align 4, !tbaa !9
  br label %17, !llvm.loop !13

67:                                               ; preds = %21
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %5, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %5, align 4, !tbaa !9
  br label %11, !llvm.loop !14

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

72:                                               ; preds = %102, %71
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = load i32, ptr @n, align 4, !tbaa !9
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %77, label %76

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

77:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %98, %77
  %79 = load i32, ptr %10, align 4, !tbaa !9
  %80 = load i32, ptr @n, align 4, !tbaa !9
  %81 = icmp slt i32 %79, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %78
  store i32 14, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %101

83:                                               ; preds = %78
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [32 x [32 x i32]], ptr @res, i64 0, i64 %85
  %87 = load i32, ptr %10, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [32 x i32], ptr %86, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !9
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = load i32, ptr %9, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [32 x i32], ptr %91, i64 %93
  %95 = load i32, ptr %10, align 4, !tbaa !9
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [32 x i32], ptr %94, i64 0, i64 %96
  store i32 %90, ptr %97, align 4, !tbaa !9
  br label %98

98:                                               ; preds = %83
  %99 = load i32, ptr %10, align 4, !tbaa !9
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %10, align 4, !tbaa !9
  br label %78, !llvm.loop !15

101:                                              ; preds = %82
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %9, align 4, !tbaa !9
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %9, align 4, !tbaa !9
  br label %72, !llvm.loop !16

105:                                              ; preds = %76
  ret void
}

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

@res = external dso_local global [32 x [32 x i32]], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global i32, align 4

; 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 @_Z3mulPA32_iS0_(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.preheader29, label %._crit_edge39

.preheader29:                                     ; preds = %2, %._crit_edge33
  %5 = phi i32 [ %8, %._crit_edge33 ], [ %3, %2 ]
  %indvar = phi i64 [ %indvar.next, %._crit_edge33 ], [ 0, %2 ]
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph32.split, label %._crit_edge33

.preheader28:                                     ; preds = %._crit_edge33
  %7 = icmp sgt i32 %8, 0
  br i1 %7, label %.preheader, label %._crit_edge39

._crit_edge33:                                    ; preds = %._crit_edge, %.preheader29
  %8 = phi i32 [ %5, %.preheader29 ], [ %15, %._crit_edge ]
  %indvar.next = add nuw nsw i64 %indvar, 1
  %9 = sext i32 %8 to i64
  %10 = icmp slt i64 %indvar.next, %9
  br i1 %10, label %.preheader29, label %.preheader28, !llvm.loop !9

.lr.ph32.split:                                   ; preds = %.preheader29, %._crit_edge
  %11 = phi i32 [ %15, %._crit_edge ], [ %5, %.preheader29 ]
  %12 = phi i32 [ %16, %._crit_edge ], [ %5, %.preheader29 ]
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %._crit_edge ], [ 0, %.preheader29 ]
  %13 = getelementptr inbounds [32 x [32 x i32]], ptr @res, i64 0, i64 %indvar, i64 %indvars.iv45
  store i32 0, ptr %13, align 4, !tbaa !5
  %14 = icmp sgt i32 %12, 0
  br i1 %14, label %.lr.ph, label %.lr.ph32.split.._crit_edge_crit_edge

.lr.ph32.split.._crit_edge_crit_edge:             ; preds = %.lr.ph32.split
  %.pre = sext i32 %12 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph32.split.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.lr.ph32.split.._crit_edge_crit_edge ], [ %26, %.lr.ph ]
  %15 = phi i32 [ %11, %.lr.ph32.split.._crit_edge_crit_edge ], [ %25, %.lr.ph ]
  %16 = phi i32 [ %12, %.lr.ph32.split.._crit_edge_crit_edge ], [ %25, %.lr.ph ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %17 = icmp slt i64 %indvars.iv.next46, %.pre-phi
  br i1 %17, label %.lr.ph32.split, label %._crit_edge33, !llvm.loop !12

.lr.ph:                                           ; preds = %.lr.ph32.split, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph32.split ]
  %18 = getelementptr inbounds [32 x i32], ptr %0, i64 %indvar, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds [32 x i32], ptr %1, i64 %indvars.iv, i64 %indvars.iv45
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = mul nsw i32 %21, %19
  %23 = load i32, ptr @p, align 4, !tbaa !5
  %24 = srem i32 %22, %23
  tail call void @_Z3addRii(ptr noundef nonnull align 4 dereferenceable(4) %13, i32 noundef %24)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next, %26
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !13

.preheader:                                       ; preds = %.preheader28, %._crit_edge37
  %28 = phi i32 [ %30, %._crit_edge37 ], [ %8, %.preheader28 ]
  %indvars.iv52 = phi i64 [ %indvars.iv.next53, %._crit_edge37 ], [ 0, %.preheader28 ]
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph36, label %.preheader.._crit_edge37_crit_edge

.preheader.._crit_edge37_crit_edge:               ; preds = %.preheader
  %.pre55 = sext i32 %28 to i64
  br label %._crit_edge37

._crit_edge39:                                    ; preds = %._crit_edge37, %2, %.preheader28
  ret void

._crit_edge37:                                    ; preds = %.lr.ph36, %.preheader.._crit_edge37_crit_edge
  %.pre-phi56 = phi i64 [ %.pre55, %.preheader.._crit_edge37_crit_edge ], [ %36, %.lr.ph36 ]
  %30 = phi i32 [ %28, %.preheader.._crit_edge37_crit_edge ], [ %35, %.lr.ph36 ]
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %31 = icmp slt i64 %indvars.iv.next53, %.pre-phi56
  br i1 %31, label %.preheader, label %._crit_edge39, !llvm.loop !14

.lr.ph36:                                         ; preds = %.preheader, %.lr.ph36
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %.lr.ph36 ], [ 0, %.preheader ]
  %32 = getelementptr inbounds [32 x [32 x i32]], ptr @res, i64 0, i64 %indvars.iv52, i64 %indvars.iv49
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = getelementptr inbounds [32 x i32], ptr %0, i64 %indvars.iv52, i64 %indvars.iv49
  store i32 %33, ptr %34, align 4, !tbaa !5
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next50, %36
  br i1 %37, label %.lr.ph36, label %._crit_edge37, !llvm.loop !15
}

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, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}
!12 = distinct !{!12, !10, !11}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !11}
!15 = distinct !{!15, !10}


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