; LLVM IR from tangjz/acm-icpc :: 51nod/1223.ll (Z5calc1ii)

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

@cnt = external dso_local global i32, align 4
@d = external dso_local global [11 x i32], align 16
@T = external dso_local global i64, align 8

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

11:                                               ; preds = %47, %2
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %50

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  store i8 1, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %32, %16
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = load i32, ptr @cnt, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 5, ptr %7, align 4
  br label %35

22:                                               ; preds = %17
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [11 x i32], ptr @d, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = srem i32 %23, %27
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %22
  store i8 0, ptr %8, align 1, !tbaa !11
  store i32 5, ptr %7, align 4
  br label %35

31:                                               ; preds = %22
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %9, align 4, !tbaa !5
  br label %17, !llvm.loop !13

35:                                               ; preds = %30, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %36

36:                                               ; preds = %35
  %37 = load i8, ptr %8, align 1, !tbaa !11, !range !15, !noundef !16
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %46

39:                                               ; preds = %36
  %40 = load i64, ptr @T, align 8, !tbaa !9
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = sdiv i64 %40, %42
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = add nsw i64 %44, %43
  store i64 %45, ptr %5, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %39, %36
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !5
  br label %11, !llvm.loop !17

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

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !14}


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

@cnt = external dso_local local_unnamed_addr global i32, align 4
@d = external dso_local local_unnamed_addr global [11 x i32], align 16
@T = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z5calc1ii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not18 = icmp sgt i32 %0, %1
  br i1 %.not18, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %3 = load i32, ptr @cnt, align 4, !tbaa !5
  %.not1516 = icmp slt i32 %3, 1
  %4 = load i64, ptr @T, align 8
  br i1 %.not1516, label %.preheader.us.preheader, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %5 = add nuw i32 %3, 1
  %6 = sext i32 %0 to i64
  %7 = add i32 %1, 1
  %wide.trip.count = zext i32 %5 to i64
  br label %.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %8 = sext i32 %0 to i64
  %9 = add i32 %1, 1
  %10 = sub i32 %9, %0
  %11 = sub i32 %1, %0
  %xtraiter = and i32 %10, 3
  %12 = icmp ult i32 %11, 3
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.preheader.us.preheader.new

.preheader.us.preheader.new:                      ; preds = %.preheader.us.preheader
  %unroll_iter = and i32 %10, -4
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us, %.preheader.us.preheader.new
  %indvars.iv27 = phi i64 [ %8, %.preheader.us.preheader.new ], [ %indvars.iv.next28.3, %.preheader.us ]
  %.01419.us = phi i64 [ 0, %.preheader.us.preheader.new ], [ %20, %.preheader.us ]
  %niter = phi i32 [ 0, %.preheader.us.preheader.new ], [ %niter.next.3, %.preheader.us ]
  %13 = sdiv i64 %4, %indvars.iv27
  %14 = add nsw i64 %13, %.01419.us
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, 1
  %15 = sdiv i64 %4, %indvars.iv.next28
  %16 = add nsw i64 %15, %14
  %indvars.iv.next28.1 = add nsw i64 %indvars.iv27, 2
  %17 = sdiv i64 %4, %indvars.iv.next28.1
  %18 = add nsw i64 %17, %16
  %indvars.iv.next28.2 = add nsw i64 %indvars.iv27, 3
  %19 = sdiv i64 %4, %indvars.iv.next28.2
  %20 = add nsw i64 %19, %18
  %indvars.iv.next28.3 = add nsw i64 %indvars.iv27, 4
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit
  %indvars.iv23 = phi i64 [ %6, %.preheader.preheader ], [ %indvars.iv.next24, %.loopexit ]
  %.01419 = phi i64 [ 0, %.preheader.preheader ], [ %.1, %.loopexit ]
  %21 = trunc nsw i64 %indvars.iv23 to i32
  br label %25

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.preheader.us, %.preheader.us.preheader
  %.lcssa.ph = phi i64 [ poison, %.preheader.us.preheader ], [ %20, %.preheader.us ]
  %indvars.iv27.unr = phi i64 [ %8, %.preheader.us.preheader ], [ %indvars.iv.next28.3, %.preheader.us ]
  %.01419.us.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %20, %.preheader.us ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge.loopexit.unr-lcssa, %.preheader.us.epil
  %indvars.iv27.epil = phi i64 [ %indvars.iv.next28.epil, %.preheader.us.epil ], [ %indvars.iv27.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01419.us.epil = phi i64 [ %23, %.preheader.us.epil ], [ %.01419.us.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.preheader.us.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %22 = sdiv i64 %4, %indvars.iv27.epil
  %23 = add nsw i64 %22, %.01419.us.epil
  %indvars.iv.next28.epil = add nsw i64 %indvars.iv27.epil, 1
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.preheader.us.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %._crit_edge.loopexit.unr-lcssa, %.preheader.us.epil, %2
  %.014.lcssa = phi i64 [ 0, %2 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %23, %.preheader.us.epil ], [ %.1, %.loopexit ]
  ret i64 %.014.lcssa

24:                                               ; preds = %25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %..critedge_crit_edge, label %25, !llvm.loop !13

25:                                               ; preds = %.preheader, %24
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next, %24 ]
  %26 = getelementptr inbounds [11 x i32], ptr @d, i64 0, i64 %indvars.iv
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = srem i32 %21, %27
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %.loopexit, label %24

..critedge_crit_edge:                             ; preds = %24
  %30 = sdiv i64 %4, %indvars.iv23
  %31 = add nsw i64 %30, %.01419
  br label %.loopexit

.loopexit:                                        ; preds = %25, %..critedge_crit_edge
  %.1 = phi i64 [ %31, %..critedge_crit_edge ], [ %.01419, %25 ]
  %indvars.iv.next24 = add nsw i64 %indvars.iv23, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next24 to i32
  %exitcond26.not = icmp eq i32 %7, %lftr.wideiv
  br i1 %exitcond26.not, label %._crit_edge, label %.preheader, !llvm.loop !9
}

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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}


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