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

; 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
@s = external dso_local global [100010 x i8], align 16
@h1 = external dso_local global [100010 x i64], align 16
@h2 = external dso_local global [100010 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10preprocessv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i64 0, ptr @h1, 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 = %25, %0
  %4 = load i32, ptr %1, align 4, !tbaa !9
  %5 = load i32, ptr @n, align 4, !tbaa !9
  %6 = icmp sle 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 %28

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 [100010 x i64], ptr @h1, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = mul i64 %13, 31
  %15 = load i32, ptr %1, align 4, !tbaa !9
  %16 = sub nsw i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100010 x i8], ptr @s, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = sext i8 %19 to i64
  %21 = add i64 %14, %20
  %22 = load i32, ptr %1, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100010 x i64], ptr @h1, i64 0, i64 %23
  store i64 %21, ptr %24, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %8
  %26 = load i32, ptr %1, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %1, align 4, !tbaa !9
  br label %3, !llvm.loop !12

28:                                               ; preds = %7
  %29 = load i32, ptr @n, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100010 x i64], ptr @h2, i64 0, i64 %31
  store i64 0, ptr %32, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %33 = load i32, ptr @n, align 4, !tbaa !9
  store i32 %33, ptr %2, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %55, %28
  %35 = load i32, ptr %2, align 4, !tbaa !9
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %58

38:                                               ; preds = %34
  %39 = load i32, ptr %2, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100010 x i64], ptr @h2, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = mul i64 %43, 31
  %45 = load i32, ptr %2, align 4, !tbaa !9
  %46 = sub nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100010 x i8], ptr @s, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = sext i8 %49 to i64
  %51 = add i64 %44, %50
  %52 = load i32, ptr %2, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100010 x i64], ptr @h2, i64 0, i64 %53
  store i64 %51, ptr %54, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %38
  %56 = load i32, ptr %2, align 4, !tbaa !9
  %57 = add nsw i32 %56, -1
  store i32 %57, ptr %2, align 4, !tbaa !9
  br label %34, !llvm.loop !14

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


; 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
@s = external dso_local local_unnamed_addr global [100010 x i8], align 16
@h1 = external dso_local local_unnamed_addr global [100010 x i64], align 16
@h2 = external dso_local local_unnamed_addr global [100010 x i64], align 16

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

._crit_edge.thread:                               ; preds = %0
  %2 = sext i32 %.pre to i64
  %3 = getelementptr inbounds [100010 x i64], ptr @h2, i64 0, i64 %2
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %._crit_edge17

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext i32 %.pre to i64
  %4 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %4, 1
  %5 = icmp eq i32 %.pre, 2
  br i1 %5, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

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

._crit_edge.unr-lcssa.loopexit:                   ; preds = %.lr.ph
  %6 = mul i64 %30, 31
  br label %._crit_edge.unr-lcssa

._crit_edge.unr-lcssa:                            ; preds = %._crit_edge.unr-lcssa.loopexit, %.lr.ph.preheader
  %.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %6, %._crit_edge.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.1, %._crit_edge.unr-lcssa.loopexit ]
  %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.unr-lcssa
  %7 = add nsw i64 %indvars.iv.unr, -1
  %8 = getelementptr inbounds [100010 x i8], ptr @s, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !11
  %10 = sext i8 %9 to i64
  %11 = add i64 %.unr, %10
  %12 = getelementptr inbounds [100010 x i64], ptr @h1, 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, %.lr.ph.epil
  %13 = sext i32 %.pre to i64
  %14 = getelementptr inbounds [100010 x i64], ptr @h2, i64 0, i64 %13
  store i64 0, ptr %14, align 8, !tbaa !5
  %15 = zext nneg i32 %1 to i64
  %16 = shl nuw nsw i64 %15, 3
  %17 = getelementptr i8, ptr @h2, i64 %16
  %scevgep = getelementptr i8, ptr %17, i64 8
  %load_initial = load i64, ptr %scevgep, align 8
  br label %.lr.ph16

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %18 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %30, %.lr.ph ]
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %19 = add nsw i64 %indvars.iv, -1
  %20 = mul i64 %18, 31
  %21 = getelementptr inbounds [100010 x i8], ptr @s, i64 0, i64 %19
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = sext i8 %22 to i64
  %24 = add i64 %20, %23
  %25 = getelementptr inbounds [100010 x i64], ptr @h1, i64 0, i64 %indvars.iv
  store i64 %24, ptr %25, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = mul i64 %24, 31
  %27 = getelementptr inbounds [100010 x i8], ptr @s, i64 0, i64 %indvars.iv
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i64
  %30 = add i64 %26, %29
  %31 = getelementptr inbounds [100010 x i64], ptr @h1, i64 0, i64 %indvars.iv.next
  store i64 %30, ptr %31, 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.loopexit, label %.lr.ph, !llvm.loop !12

._crit_edge17:                                    ; preds = %.lr.ph16, %._crit_edge.thread
  ret void

.lr.ph16:                                         ; preds = %._crit_edge, %.lr.ph16
  %store_forwarded = phi i64 [ %load_initial, %._crit_edge ], [ %36, %.lr.ph16 ]
  %indvars.iv19 = phi i64 [ %15, %._crit_edge ], [ %indvars.iv.next20, %.lr.ph16 ]
  %32 = mul i64 %store_forwarded, 31
  %indvars.iv.next20 = add nsw i64 %indvars.iv19, -1
  %33 = getelementptr inbounds [100010 x i8], ptr @s, i64 0, i64 %indvars.iv.next20
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = sext i8 %34 to i64
  %36 = add i64 %32, %35
  %37 = getelementptr inbounds [100010 x i64], ptr @h2, i64 0, i64 %indvars.iv19
  store i64 %36, ptr %37, align 8, !tbaa !5
  %38 = icmp ugt i64 %indvars.iv19, 1
  br i1 %38, label %.lr.ph16, label %._crit_edge17, !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,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass