; LLVM IR from kazunetakahashi/atcoder :: 2019/0609_ABC129/past/F2.ll (Z6choosexx)

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

%struct.matrix = type { i32, i32, %"class.std::valarray" }
%"class.std::valarray" = type { i64, ptr }
%"class.std::initializer_list" = type { ptr, i64 }

@MOD = external dso_local global i64, align 8
@B = external dso_local global i64, align 8

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6matrixC2Eii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6matrixC2ERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7mod_pow6matrixx(ptr dead_on_unwind noalias writable sret(%struct.matrix) align 8, ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6choosexx(ptr dead_on_unwind noalias writable sret(%struct.matrix) align 8 %0, i64 noundef %1, i64 noundef %2) #1 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.matrix, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca %"class.std::initializer_list", align 8
  %11 = alloca [9 x i64], align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca %struct.matrix, align 8
  store ptr %0, ptr %4, align 8
  store i64 %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  call void @_ZN6matrixC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %7, i32 noundef 3, i32 noundef 3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 1, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %24, %3
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = icmp slt i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %27

21:                                               ; preds = %15
  %22 = load i64, ptr %8, align 8, !tbaa !5
  %23 = mul nsw i64 %22, 10
  store i64 %23, ptr %8, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %21
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %9, align 4, !tbaa !9
  br label %15, !llvm.loop !11

27:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 72, ptr %11) #4
  %28 = load i64, ptr %8, align 8, !tbaa !5
  %29 = load i64, ptr @MOD, align 8, !tbaa !5
  %30 = srem i64 %28, %29
  store i64 %30, ptr %11, align 8, !tbaa !5
  %31 = getelementptr inbounds i64, ptr %11, i64 1
  store i64 1, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds i64, ptr %11, i64 2
  store i64 0, ptr %32, align 8, !tbaa !5
  %33 = getelementptr inbounds i64, ptr %11, i64 3
  store i64 0, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds i64, ptr %11, i64 4
  store i64 1, ptr %34, align 8, !tbaa !5
  %35 = getelementptr inbounds i64, ptr %11, i64 5
  %36 = load i64, ptr @B, align 8, !tbaa !5
  store i64 %36, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds i64, ptr %11, i64 6
  store i64 0, ptr %37, align 8, !tbaa !5
  %38 = getelementptr inbounds i64, ptr %11, i64 7
  store i64 0, ptr %38, align 8, !tbaa !5
  %39 = getelementptr inbounds i64, ptr %11, i64 8
  store i64 1, ptr %39, align 8, !tbaa !5
  %40 = getelementptr inbounds %"class.std::initializer_list", ptr %10, i32 0, i32 0
  store ptr %11, ptr %40, align 8, !tbaa !13
  %41 = getelementptr inbounds %"class.std::initializer_list", ptr %10, i32 0, i32 1
  store i64 9, ptr %41, align 8, !tbaa !17
  %42 = getelementptr inbounds %struct.matrix, ptr %7, i32 0, i32 2
  %43 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8
  %45 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 1
  %46 = load i64, ptr %45, align 8
  %47 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIxEaSESt16initializer_listIxE(ptr noundef nonnull align 8 dereferenceable(16) %42, ptr %44, i64 %46)
          to label %48 unwind label %52

48:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 72, ptr %11) #4
  invoke void @_ZN6matrixC2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %14, ptr noundef nonnull align 8 dereferenceable(24) %7)
          to label %49 unwind label %56

49:                                               ; preds = %48
  %50 = load i64, ptr %6, align 8, !tbaa !5
  invoke void @_Z7mod_pow6matrixx(ptr dead_on_unwind writable sret(%struct.matrix) align 8 %0, ptr noundef %14, i64 noundef %50)
          to label %51 unwind label %60

51:                                               ; preds = %49
  call void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  ret void

52:                                               ; preds = %27
  %53 = landingpad { ptr, i32 }
          cleanup
  %54 = extractvalue { ptr, i32 } %53, 0
  store ptr %54, ptr %12, align 8
  %55 = extractvalue { ptr, i32 } %53, 1
  store i32 %55, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 72, ptr %11) #4
  br label %64

56:                                               ; preds = %48
  %57 = landingpad { ptr, i32 }
          cleanup
  %58 = extractvalue { ptr, i32 } %57, 0
  store ptr %58, ptr %12, align 8
  %59 = extractvalue { ptr, i32 } %57, 1
  store i32 %59, ptr %13, align 4
  br label %64

60:                                               ; preds = %49
  %61 = landingpad { ptr, i32 }
          cleanup
  %62 = extractvalue { ptr, i32 } %61, 0
  store ptr %62, ptr %12, align 8
  %63 = extractvalue { ptr, i32 } %61, 1
  store i32 %63, ptr %13, align 4
  call void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %14) #4
  br label %64

64:                                               ; preds = %60, %56, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr %12, align 8
  %67 = load i32, ptr %13, align 4
  %68 = insertvalue { ptr, i32 } poison, ptr %66, 0
  %69 = insertvalue { ptr, i32 } %68, i32 %67, 1
  resume { ptr, i32 } %69
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIxEaSESt16initializer_listIxE(ptr noundef nonnull align 8 dereferenceable(16), ptr, i64) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { inlinehint 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 #4 = { 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 = !{!14, !15, i64 0}
!14 = !{!"_ZTSSt16initializer_listIxE", !15, i64 0, !16, i64 8}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!14, !16, i64 8}


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

%struct.matrix = type { i32, i32, %"class.std::valarray" }
%"class.std::valarray" = type { i64, ptr }

@MOD = external dso_local local_unnamed_addr global i64, align 8
@B = external dso_local local_unnamed_addr global i64, align 8

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6matrixC2Eii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN6matrixC2ERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7mod_pow6matrixx(ptr dead_on_unwind noalias writable sret(%struct.matrix) align 8, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6choosexx(ptr dead_on_unwind noalias writable sret(%struct.matrix) align 8 %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %4 = alloca %struct.matrix, align 8
  %5 = alloca [9 x i64], align 8
  %6 = alloca %struct.matrix, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #5
  call void @_ZN6matrixC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %4, i32 noundef 3, i32 noundef 3)
  %7 = icmp sgt i64 %1, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

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

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

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %21, %.lr.ph ]
  %.0812.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %21, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.0812.epil = phi i64 [ %9, %.lr.ph.epil ], [ %.0812.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %9 = mul nuw nsw i64 %.0812.epil, 10
  %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_edge, label %.lr.ph.epil, !llvm.loop !5

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %3
  %.08.lcssa = phi i64 [ 1, %3 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %9, %.lr.ph.epil ]
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %5) #5
  %10 = load i64, ptr @MOD, align 8, !tbaa !7
  %11 = srem i64 %.08.lcssa, %10
  store i64 %11, ptr %5, align 8, !tbaa !7
  %12 = getelementptr inbounds i8, ptr %5, i64 8
  store i64 1, ptr %12, align 8, !tbaa !7
  %13 = getelementptr inbounds i8, ptr %5, i64 16
  %14 = getelementptr inbounds i8, ptr %5, i64 32
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %13, i8 0, i64 16, i1 false)
  store i64 1, ptr %14, align 8, !tbaa !7
  %15 = getelementptr inbounds i8, ptr %5, i64 40
  %16 = load i64, ptr @B, align 8, !tbaa !7
  store i64 %16, ptr %15, align 8, !tbaa !7
  %17 = getelementptr inbounds i8, ptr %5, i64 48
  %18 = getelementptr inbounds i8, ptr %5, i64 64
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %17, i8 0, i64 16, i1 false)
  store i64 1, ptr %18, align 8, !tbaa !7
  %19 = getelementptr inbounds i8, ptr %4, i64 8
  %20 = invoke noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIxEaSESt16initializer_listIxE(ptr noundef nonnull align 8 dereferenceable(16) %19, ptr nonnull %5, i64 9)
          to label %22 unwind label %25

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.0812 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %21, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %21 = mul nuw i64 %.0812, 100000000
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11

22:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %5) #5
  invoke void @_ZN6matrixC2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %4)
          to label %23 unwind label %27

23:                                               ; preds = %22
  invoke void @_Z7mod_pow6matrixx(ptr dead_on_unwind writable sret(%struct.matrix) align 8 %0, ptr noundef nonnull %6, i64 noundef %2)
          to label %24 unwind label %29

24:                                               ; preds = %23
  call void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %6) #5
  call void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %4) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  ret void

25:                                               ; preds = %._crit_edge
  %26 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %5) #5
  br label %31

27:                                               ; preds = %22
  %28 = landingpad { ptr, i32 }
          cleanup
  br label %31

29:                                               ; preds = %23
  %30 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %6) #5
  br label %31

31:                                               ; preds = %29, %27, %25
  %.pn = phi { ptr, i32 } [ %30, %29 ], [ %28, %27 ], [ %26, %25 ]
  call void @_ZN6matrixD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %4) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  resume { ptr, i32 } %.pn
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt8valarrayIxEaSESt16initializer_listIxE(ptr noundef nonnull align 8 dereferenceable(16), ptr, i64) local_unnamed_addr #3 align 2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { inlinehint 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.unroll.disable"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass