; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SNACKDOWN/16/Pre-Elimination A/Problem F/F.ll (Z5solvev)

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

@a = external dso_local global [100100 x i32], align 16
@s = external dso_local global [100100 x i64], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1

; 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 uwtable
declare dso_local noundef i64 @_Z3getx(i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @n, ptr noundef @m, ptr noundef %1, ptr noundef %2)
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = add nsw i64 %7, -1
  store i64 %8, ptr %1, align 8, !tbaa !5
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = add nsw i64 %9, -1
  store i64 %10, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %21, %0
  %12 = load i32, ptr %3, 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
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %24

16:                                               ; preds = %11
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %18
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef %19)
  br label %21

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

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

27:                                               ; preds = %48, %24
  %28 = load i32, ptr %4, 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 %4) #3
  br label %51

32:                                               ; preds = %27
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100100 x i64], ptr @s, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = srem i64 %42, 1000000007
  %44 = add nsw i64 %37, %43
  %45 = load i32, ptr %4, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100100 x i64], ptr @s, i64 0, i64 %46
  store i64 %44, ptr %47, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %32
  %49 = load i32, ptr %4, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !9
  br label %27, !llvm.loop !13

51:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %52 = load i64, ptr %2, align 8, !tbaa !5
  %53 = call noundef i64 @_Z3getx(i64 noundef %52)
  %54 = load i64, ptr %1, align 8, !tbaa !5
  %55 = sub nsw i64 %54, 1
  %56 = call noundef i64 @_Z3getx(i64 noundef %55)
  %57 = sub nsw i64 %53, %56
  %58 = add nsw i64 %57, 1000000007
  %59 = srem i64 %58, 1000000007
  store i64 %59, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %5, align 8, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %60)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

declare i32 @printf(ptr noundef, ...) #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 = { "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 = !{!"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 = distinct !{!13, !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"

@a = external dso_local global [100100 x i32], align 16
@s = external dso_local local_unnamed_addr global [100100 x i64], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1

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

; 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 noundef i64 @_Z3getx(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = add nsw i64 %4, -1
  store i64 %5, ptr %1, align 8, !tbaa !5
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = add nsw i64 %6, -1
  store i64 %7, ptr %2, align 8, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !9
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  %10 = load i32, ptr @a, align 16, !tbaa !9
  %11 = sext i32 %10 to i64
  store i64 %11, ptr @s, align 16, !tbaa !5
  br label %._crit_edge14

._crit_edge:                                      ; preds = %.lr.ph
  %12 = load i32, ptr @a, align 16, !tbaa !9
  %13 = sext i32 %12 to i64
  store i64 %13, ptr @s, align 16, !tbaa !5
  %14 = icmp sgt i32 %19, 1
  br i1 %14, label %.lr.ph13.preheader, label %._crit_edge14

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

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

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %17 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull %17)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr @n, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge14.loopexit.unr-lcssa:                 ; preds = %.lr.ph13, %.lr.ph13.preheader
  %.unr = phi i64 [ %13, %.lr.ph13.preheader ], [ %45, %.lr.ph13 ]
  %indvars.iv17.unr = phi i64 [ 1, %.lr.ph13.preheader ], [ %indvars.iv.next18.1, %.lr.ph13 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge14, label %.lr.ph13.epil

.lr.ph13.epil:                                    ; preds = %._crit_edge14.loopexit.unr-lcssa
  %22 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv17.unr
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = srem i32 %23, 1000000007
  %.sext.epil = sext i32 %24 to i64
  %25 = add nsw i64 %.unr, %.sext.epil
  %26 = getelementptr inbounds [100100 x i64], ptr @s, i64 0, i64 %indvars.iv17.unr
  store i64 %25, ptr %26, align 8, !tbaa !5
  br label %._crit_edge14

._crit_edge14:                                    ; preds = %.lr.ph13.epil, %._crit_edge14.loopexit.unr-lcssa, %._crit_edge.thread, %._crit_edge
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = call noundef i64 @_Z3getx(i64 noundef %27)
  %29 = load i64, ptr %1, align 8, !tbaa !5
  %30 = add nsw i64 %29, -1
  %31 = call noundef i64 @_Z3getx(i64 noundef %30)
  %32 = add i64 %28, 1000000007
  %33 = sub i64 %32, %31
  %34 = srem i64 %33, 1000000007
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %34)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret void

.lr.ph13:                                         ; preds = %.lr.ph13, %.lr.ph13.preheader.new
  %36 = phi i64 [ %13, %.lr.ph13.preheader.new ], [ %45, %.lr.ph13 ]
  %indvars.iv17 = phi i64 [ 1, %.lr.ph13.preheader.new ], [ %indvars.iv.next18.1, %.lr.ph13 ]
  %niter = phi i64 [ 0, %.lr.ph13.preheader.new ], [ %niter.next.1, %.lr.ph13 ]
  %37 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv17
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = srem i32 %38, 1000000007
  %.sext = sext i32 %39 to i64
  %40 = add nsw i64 %36, %.sext
  %41 = getelementptr inbounds [100100 x i64], ptr @s, i64 0, i64 %indvars.iv17
  store i64 %40, ptr %41, align 8, !tbaa !5
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %42 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv.next18
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = srem i32 %43, 1000000007
  %.sext.1 = sext i32 %44 to i64
  %45 = add nsw i64 %40, %.sext.1
  %46 = getelementptr inbounds [100100 x i64], ptr @s, i64 0, i64 %indvars.iv.next18
  store i64 %45, ptr %46, align 8, !tbaa !5
  %indvars.iv.next18.1 = add nuw nsw i64 %indvars.iv17, 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_edge14.loopexit.unr-lcssa, label %.lr.ph13, !llvm.loop !13
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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 = { nofree nounwind "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 = !{!"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 = distinct !{!13, !12}


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