; LLVM IR from upupming/algorithm :: kick-start/2019/2019G-A.ll (Z9solve_oldv)

; 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
@m = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@p = external dso_local global [100005 x i32], align 16
@r = external dso_local global [100005 x i32], align 16

; 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 nounwind uwtable
define dso_local noundef i32 @_Z9solve_oldv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %43, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @q, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %46

10:                                               ; preds = %5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100005 x i32], ptr @r, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sdiv i32 %11, %15
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = add nsw i32 %17, %16
  store i32 %18, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %39, %10
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr @m, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %42

24:                                               ; preds = %19
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100005 x i32], ptr @r, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = srem i32 %28, %32
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %24
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = sub nsw i32 %36, 1
  store i32 %37, ptr %1, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %35, %24
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !5
  br label %19, !llvm.loop !9

42:                                               ; preds = %23
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !11

46:                                               ; preds = %9
  %47 = load i32, ptr %1, align 4, !tbaa !5
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i32 %47
}

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


; 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
@m = external dso_local local_unnamed_addr global i32, align 4
@q = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [100005 x i32], align 16
@r = external dso_local local_unnamed_addr global [100005 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z9solve_oldv() local_unnamed_addr #0 {
  %1 = load i32, ptr @q, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph17, label %._crit_edge18

.lr.ph17:                                         ; preds = %0
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = load i32, ptr @m, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  %wide.trip.count30 = zext nneg i32 %1 to i64
  br i1 %5, label %.lr.ph.us.preheader, label %.lr.ph17.split.preheader

.lr.ph17.split.preheader:                         ; preds = %.lr.ph17
  %xtraiter = and i64 %wide.trip.count30, 1
  %6 = icmp eq i32 %1, 1
  br i1 %6, label %._crit_edge18.loopexit34.unr-lcssa, label %.lr.ph17.split.preheader.new

.lr.ph17.split.preheader.new:                     ; preds = %.lr.ph17.split.preheader
  %unroll_iter = and i64 %wide.trip.count30, 2147483646
  br label %.lr.ph17.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph17
  %wide.trip.count25 = zext nneg i32 %4 to i64
  %xtraiter36 = and i64 %wide.trip.count25, 1
  %7 = icmp eq i32 %4, 1
  %unroll_iter39 = and i64 %wide.trip.count25, 2147483646
  %lcmp.mod37.not = icmp eq i64 %xtraiter36, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv27 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next28, %._crit_edge.us ]
  %.01114.us = phi i32 [ 0, %.lr.ph.us.preheader ], [ %spec.select.us.lcssa, %._crit_edge.us ]
  %8 = getelementptr inbounds [100005 x i32], ptr @r, i64 0, i64 %indvars.iv27
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sdiv i32 %3, %9
  %11 = add nsw i32 %10, %.01114.us
  br i1 %7, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %indvars.iv22 = phi i64 [ %indvars.iv.next23.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %.112.us = phi i32 [ %spec.select.us.1, %.lr.ph.us.new ], [ %11, %.lr.ph.us ]
  %niter40 = phi i64 [ %niter40.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %12 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %indvars.iv22
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = srem i32 %13, %9
  %15 = icmp eq i32 %14, 0
  %16 = sext i1 %15 to i32
  %spec.select.us = add nsw i32 %.112.us, %16
  %indvars.iv.next23 = or disjoint i64 %indvars.iv22, 1
  %17 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %indvars.iv.next23
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = srem i32 %18, %9
  %20 = icmp eq i32 %19, 0
  %21 = sext i1 %20 to i32
  %spec.select.us.1 = add nsw i32 %spec.select.us, %21
  %indvars.iv.next23.1 = add nuw nsw i64 %indvars.iv22, 2
  %niter40.next.1 = add i64 %niter40, 2
  %niter40.ncmp.1 = icmp eq i64 %niter40.next.1, %unroll_iter39
  br i1 %niter40.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %spec.select.us.lcssa.ph = phi i32 [ poison, %.lr.ph.us ], [ %spec.select.us.1, %.lr.ph.us.new ]
  %indvars.iv22.unr = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next23.1, %.lr.ph.us.new ]
  %.112.us.unr = phi i32 [ %11, %.lr.ph.us ], [ %spec.select.us.1, %.lr.ph.us.new ]
  br i1 %lcmp.mod37.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %22 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %indvars.iv22.unr
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = srem i32 %23, %9
  %25 = icmp eq i32 %24, 0
  %26 = sext i1 %25 to i32
  %spec.select.us.epil = add nsw i32 %.112.us.unr, %26
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %spec.select.us.lcssa = phi i32 [ %spec.select.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %spec.select.us.epil, %._crit_edge.us.epilog-lcssa ]
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %exitcond31.not = icmp eq i64 %indvars.iv.next28, %wide.trip.count30
  br i1 %exitcond31.not, label %._crit_edge18, label %.lr.ph.us, !llvm.loop !11

._crit_edge18.loopexit34.unr-lcssa:               ; preds = %.lr.ph17.split, %.lr.ph17.split.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph17.split.preheader ], [ %38, %.lr.ph17.split ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph17.split.preheader ], [ %indvars.iv.next.1, %.lr.ph17.split ]
  %.01114.unr = phi i32 [ 0, %.lr.ph17.split.preheader ], [ %38, %.lr.ph17.split ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge18, label %.lr.ph17.split.epil

.lr.ph17.split.epil:                              ; preds = %._crit_edge18.loopexit34.unr-lcssa
  %27 = getelementptr inbounds [100005 x i32], ptr @r, i64 0, i64 %indvars.iv.unr
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sdiv i32 %3, %28
  %30 = add nsw i32 %29, %.01114.unr
  br label %._crit_edge18

._crit_edge18:                                    ; preds = %.lr.ph17.split.epil, %._crit_edge18.loopexit34.unr-lcssa, %._crit_edge.us, %0
  %.011.lcssa = phi i32 [ 0, %0 ], [ %spec.select.us.lcssa, %._crit_edge.us ], [ %.lcssa.ph, %._crit_edge18.loopexit34.unr-lcssa ], [ %30, %.lr.ph17.split.epil ]
  ret i32 %.011.lcssa

.lr.ph17.split:                                   ; preds = %.lr.ph17.split, %.lr.ph17.split.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph17.split.preheader.new ], [ %indvars.iv.next.1, %.lr.ph17.split ]
  %.01114 = phi i32 [ 0, %.lr.ph17.split.preheader.new ], [ %38, %.lr.ph17.split ]
  %niter = phi i64 [ 0, %.lr.ph17.split.preheader.new ], [ %niter.next.1, %.lr.ph17.split ]
  %31 = getelementptr inbounds [100005 x i32], ptr @r, i64 0, i64 %indvars.iv
  %32 = load i32, ptr %31, align 8, !tbaa !5
  %33 = sdiv i32 %3, %32
  %34 = add nsw i32 %33, %.01114
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %35 = getelementptr inbounds [100005 x i32], ptr @r, i64 0, i64 %indvars.iv.next
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sdiv i32 %3, %36
  %38 = add nsw i32 %37, %34
  %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_edge18.loopexit34.unr-lcssa, label %.lr.ph17.split, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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