; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SHORT/COOK70/Problem D/D.ll (Z10precomputev)

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

@b = external dso_local global i64, align 8
@p = external dso_local global i64, align 8
@h = external dso_local global [200100 x i64], align 16
@pwr = external dso_local global [200100 x i64], align 16
@n = external dso_local global i32, align 4
@s = external dso_local global [200100 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10precomputev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i64 1, ptr @pwr, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 1, ptr %1, align 4, !tbaa !9
  br label %3

3:                                                ; preds = %21, %0
  %4 = load i32, ptr %1, align 4, !tbaa !9
  %5 = load i32, ptr @n, align 4, !tbaa !9
  %6 = icmp slt i32 %4, %5
  br i1 %6, label %8, label %7

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

8:                                                ; preds = %3
  %9 = load i32, ptr %1, align 4, !tbaa !9
  %10 = sub nsw i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [200100 x i64], ptr @pwr, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = load i64, ptr @b, align 8, !tbaa !5
  %15 = mul nsw i64 %13, %14
  %16 = load i64, ptr @p, align 8, !tbaa !5
  %17 = srem i64 %15, %16
  %18 = load i32, ptr %1, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [200100 x i64], ptr @pwr, i64 0, i64 %19
  store i64 %17, ptr %20, align 8, !tbaa !5
  br label %21

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

24:                                               ; preds = %7
  %25 = load i8, ptr @s, align 16, !tbaa !13
  %26 = sext i8 %25 to i64
  store i64 %26, ptr @h, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %51, %24
  %28 = load i32, ptr %2, align 4, !tbaa !9
  %29 = load i32, ptr @n, align 4, !tbaa !9
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %54

32:                                               ; preds = %27
  %33 = load i32, ptr %2, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [200100 x i64], ptr @h, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = load i64, ptr @b, align 8, !tbaa !5
  %39 = mul nsw i64 %37, %38
  %40 = load i32, ptr %2, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200100 x i8], ptr @s, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = sext i8 %43 to i64
  %45 = add nsw i64 %39, %44
  %46 = load i64, ptr @p, align 8, !tbaa !5
  %47 = srem i64 %45, %46
  %48 = load i32, ptr %2, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200100 x i64], ptr @h, i64 0, i64 %49
  store i64 %47, ptr %50, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %32
  %52 = load i32, ptr %2, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %2, align 4, !tbaa !9
  br label %27, !llvm.loop !14

54:                                               ; preds = %31
  ret void
}

; 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

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 = !{!7, !7, i64 0}
!14 = distinct !{!14, !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"

@b = external dso_local local_unnamed_addr global i64, align 8
@p = external dso_local local_unnamed_addr global i64, align 8
@h = external dso_local local_unnamed_addr global [200100 x i64], align 16
@pwr = external dso_local local_unnamed_addr global [200100 x i64], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [200100 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z10precomputev() local_unnamed_addr #0 {
  store i64 1, ptr @pwr, align 16, !tbaa !5
  %1 = load i32, ptr @n, align 4, !tbaa !9
  %2 = icmp sgt i32 %1, 1
  br i1 %2, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  %3 = load i8, ptr @s, align 16, !tbaa !11
  %4 = sext i8 %3 to i64
  store i64 %4, ptr @h, align 16, !tbaa !5
  br label %._crit_edge14

.lr.ph:                                           ; preds = %0
  %5 = load i64, ptr @b, align 8, !tbaa !5
  %6 = load i64, ptr @p, align 8, !tbaa !5
  %wide.trip.count = zext nneg i32 %1 to i64
  %7 = add nsw i64 %wide.trip.count, -1
  %8 = add nsw i64 %wide.trip.count, -2
  %xtraiter = and i64 %7, 1
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %._crit_edge.unr-lcssa, label %.lr.ph.new

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

._crit_edge.unr-lcssa:                            ; preds = %18, %.lr.ph
  %.unr = phi i64 [ 1, %.lr.ph ], [ %24, %18 ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next.1, %18 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %10 = mul nsw i64 %5, %.unr
  %11 = srem i64 %10, %6
  %12 = getelementptr inbounds [200100 x i64], ptr @pwr, i64 0, i64 %indvars.iv.unr
  store i64 %11, ptr %12, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %13 = load i8, ptr @s, align 16, !tbaa !11
  %14 = sext i8 %13 to i64
  store i64 %14, ptr @h, align 16, !tbaa !5
  br i1 %2, label %.lr.ph13, label %._crit_edge14

.lr.ph13:                                         ; preds = %._crit_edge
  %15 = load i64, ptr @b, align 8, !tbaa !5
  %16 = load i64, ptr @p, align 8, !tbaa !5
  %xtraiter22 = and i64 %7, 1
  %17 = icmp eq i64 %8, 0
  br i1 %17, label %._crit_edge14.loopexit.unr-lcssa, label %.lr.ph13.new

.lr.ph13.new:                                     ; preds = %.lr.ph13
  %unroll_iter25 = and i64 %7, -2
  br label %33

18:                                               ; preds = %18, %.lr.ph.new
  %19 = phi i64 [ 1, %.lr.ph.new ], [ %24, %18 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.1, %18 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %18 ]
  %20 = mul nsw i64 %5, %19
  %21 = srem i64 %20, %6
  %22 = getelementptr inbounds [200100 x i64], ptr @pwr, i64 0, i64 %indvars.iv
  store i64 %21, ptr %22, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = mul nsw i64 %5, %21
  %24 = srem i64 %23, %6
  %25 = getelementptr inbounds [200100 x i64], ptr @pwr, i64 0, i64 %indvars.iv.next
  store i64 %24, ptr %25, align 8, !tbaa !5
  %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 %._crit_edge.unr-lcssa, label %18, !llvm.loop !12

._crit_edge14.loopexit.unr-lcssa:                 ; preds = %33, %.lr.ph13
  %.unr23 = phi i64 [ %14, %.lr.ph13 ], [ %47, %33 ]
  %indvars.iv16.unr = phi i64 [ 1, %.lr.ph13 ], [ %indvars.iv.next17.1, %33 ]
  %lcmp.mod24.not = icmp eq i64 %xtraiter22, 0
  br i1 %lcmp.mod24.not, label %._crit_edge14, label %._crit_edge14.loopexit.epilog-lcssa

._crit_edge14.loopexit.epilog-lcssa:              ; preds = %._crit_edge14.loopexit.unr-lcssa
  %26 = mul nsw i64 %15, %.unr23
  %27 = getelementptr inbounds [200100 x i8], ptr @s, i64 0, i64 %indvars.iv16.unr
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i64
  %30 = add nsw i64 %26, %29
  %31 = srem i64 %30, %16
  %32 = getelementptr inbounds [200100 x i64], ptr @h, i64 0, i64 %indvars.iv16.unr
  store i64 %31, ptr %32, align 8, !tbaa !5
  br label %._crit_edge14

._crit_edge14:                                    ; preds = %._crit_edge14.loopexit.epilog-lcssa, %._crit_edge14.loopexit.unr-lcssa, %._crit_edge.thread, %._crit_edge
  ret void

33:                                               ; preds = %33, %.lr.ph13.new
  %34 = phi i64 [ %14, %.lr.ph13.new ], [ %47, %33 ]
  %indvars.iv16 = phi i64 [ 1, %.lr.ph13.new ], [ %indvars.iv.next17.1, %33 ]
  %niter26 = phi i64 [ 0, %.lr.ph13.new ], [ %niter26.next.1, %33 ]
  %35 = mul nsw i64 %15, %34
  %36 = getelementptr inbounds [200100 x i8], ptr @s, i64 0, i64 %indvars.iv16
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i64
  %39 = add nsw i64 %35, %38
  %40 = srem i64 %39, %16
  %41 = getelementptr inbounds [200100 x i64], ptr @h, i64 0, i64 %indvars.iv16
  store i64 %40, ptr %41, align 8, !tbaa !5
  %indvars.iv.next17 = add nuw nsw i64 %indvars.iv16, 1
  %42 = mul nsw i64 %15, %40
  %43 = getelementptr inbounds [200100 x i8], ptr @s, i64 0, i64 %indvars.iv.next17
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = sext i8 %44 to i64
  %46 = add nsw i64 %42, %45
  %47 = srem i64 %46, %16
  %48 = getelementptr inbounds [200100 x i64], ptr @h, i64 0, i64 %indvars.iv.next17
  store i64 %47, ptr %48, align 8, !tbaa !5
  %indvars.iv.next17.1 = add nuw nsw i64 %indvars.iv16, 2
  %niter26.next.1 = add i64 %niter26, 2
  %niter26.ncmp.1 = icmp eq i64 %niter26.next.1, %unroll_iter25
  br i1 %niter26.ncmp.1, label %._crit_edge14.loopexit.unr-lcssa, label %33, !llvm.loop !14
}

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

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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