; LLVM IR from tangjz/acm-icpc :: codeforces/gym/101194I.ll (Z6solve1v)

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

@n = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@c = external dso_local global [101 x i32], align 16
@coeff = external dso_local global [2 x [10001 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, 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
declare dso_local void @_Z5solveii(i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z6solve1v() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = load i32, ptr @p, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 100
  br i1 %5, label %6, label %27

6:                                                ; preds = %0
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = load i32, ptr @c, align 16, !tbaa !5
  %9 = srem i32 %7, %8
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %23

11:                                               ; preds = %6
  %12 = load i32, ptr @c, align 16, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = load i32, ptr @c, align 16, !tbaa !5
  %15 = srem i32 %13, %14
  %16 = sub nsw i32 %12, %15
  %17 = sext i32 %16 to i64
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = call noundef i32 @_Z7mod_powii(i32 noundef 100, i32 noundef %18)
  %20 = sext i32 %19 to i64
  %21 = mul nsw i64 %17, %20
  %22 = srem i64 %21, 1000000007
  br label %24

23:                                               ; preds = %6
  br label %24

24:                                               ; preds = %23, %11
  %25 = phi i64 [ %22, %11 ], [ 0, %23 ]
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %1, align 4
  br label %55

27:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  %28 = load i32, ptr @n, align 4, !tbaa !5
  call void @_Z5solveii(i32 noundef 0, i32 noundef %28)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %50, %27
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr @c, align 16, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %53

34:                                               ; preds = %29
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = load i32, ptr @c, align 16, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sub nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [10001 x i32], ptr @coeff, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = mul nsw i64 %40, %45
  %47 = add nsw i64 %36, %46
  %48 = srem i64 %47, 1000000007
  %49 = trunc i64 %48 to i32
  store i32 %49, ptr %2, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %34
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %3, align 4, !tbaa !5
  br label %29, !llvm.loop !9

53:                                               ; preds = %33
  %54 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %54, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %55

55:                                               ; preds = %53, %24
  %56 = load i32, ptr %1, align 4
  ret i32 %56
}

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


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

@n = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global i32, align 4
@c = external dso_local local_unnamed_addr global [101 x i32], align 16
@coeff = external dso_local local_unnamed_addr global [2 x [10001 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solveii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -1000000006, 1000000007) i32 @_Z6solve1v() local_unnamed_addr #1 {
  %1 = load i32, ptr @p, align 4, !tbaa !5
  %2 = icmp eq i32 %1, 100
  %3 = load i32, ptr @n, align 4, !tbaa !5
  br i1 %2, label %4, label %15

4:                                                ; preds = %0
  %5 = load i32, ptr @c, align 16, !tbaa !5
  %6 = srem i32 %3, %5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.loopexit, label %7

7:                                                ; preds = %4
  %8 = sub nsw i32 %5, %6
  %9 = sext i32 %8 to i64
  %10 = tail call noundef i32 @_Z7mod_powii(i32 noundef 100, i32 noundef %3)
  %11 = sext i32 %10 to i64
  %12 = mul nsw i64 %11, %9
  %13 = srem i64 %12, 1000000007
  %14 = trunc nsw i64 %13 to i32
  br label %.loopexit

15:                                               ; preds = %0
  tail call void @_Z5solveii(i32 noundef 0, i32 noundef %3)
  %16 = load i32, ptr @c, align 16, !tbaa !5
  %17 = icmp sgt i32 %16, 1
  br i1 %17, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %15
  %18 = zext nneg i32 %16 to i64
  %wide.trip.count = zext nneg i32 %16 to i64
  %19 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %19, 1
  %20 = icmp eq i32 %16, 2
  br i1 %20, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

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

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.0711 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %21 = sub nsw i64 %18, %indvars.iv
  %22 = getelementptr inbounds [10001 x i32], ptr @coeff, i64 0, i64 %indvars.iv
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %21, %24
  %26 = add nsw i64 %25, %.0711
  %27 = srem i64 %26, 1000000007
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %28 = sub nsw i64 %18, %indvars.iv.next
  %29 = getelementptr inbounds [10001 x i32], ptr @coeff, i64 0, i64 %indvars.iv.next
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = mul nsw i64 %28, %31
  %33 = add nsw i64 %32, %27
  %34 = srem i64 %33, 1000000007
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

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

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa
  %35 = sub nsw i64 %18, %indvars.iv.unr
  %36 = getelementptr inbounds [10001 x i32], ptr @coeff, i64 0, i64 %indvars.iv.unr
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %35, %38
  %40 = add nsw i64 %39, %.0711.unr
  %41 = srem i64 %40, 1000000007
  br label %.loopexit.loopexit

.loopexit.loopexit:                               ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil
  %.lcssa = phi i64 [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %41, %.lr.ph.epil ]
  %42 = trunc nsw i64 %.lcssa to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %15, %7, %4
  %.08 = phi i32 [ %14, %7 ], [ 0, %4 ], [ 0, %15 ], [ %42, %.loopexit.loopexit ]
  ret i32 %.08
}

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

!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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass