; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/DIGCNT/A.ll (Z1slll)

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

@d = external dso_local global i64, align 8
@B = external dso_local global i64, align 8
@f = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z1slll(i64 noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !5
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = load i64, ptr %5, align 8, !tbaa !5
  %10 = icmp sgt i64 %8, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  store i64 0, ptr %4, align 8
  br label %49

12:                                               ; preds = %3
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = load i64, ptr %7, align 8, !tbaa !5
  %15 = sdiv i64 %13, %14
  %16 = srem i64 %15, 10
  store i64 %16, ptr @B, align 8, !tbaa !5
  %17 = load i64, ptr %7, align 8, !tbaa !5
  %18 = load i64, ptr @f, align 8, !tbaa !5
  %19 = sdiv i64 %17, %18
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = mul nsw i64 %19, %20
  %22 = load i64, ptr @B, align 8, !tbaa !5
  %23 = mul nsw i64 %21, %22
  %24 = load i64, ptr %7, align 8, !tbaa !5
  %25 = load i64, ptr @d, align 8, !tbaa !5
  %26 = load i64, ptr @B, align 8, !tbaa !5
  %27 = icmp slt i64 %25, %26
  %28 = zext i1 %27 to i64
  %29 = mul nsw i64 %24, %28
  %30 = add nsw i64 %23, %29
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %7, align 8, !tbaa !5
  %33 = srem i64 %31, %32
  %34 = add nsw i64 %33, 1
  %35 = load i64, ptr @d, align 8, !tbaa !5
  %36 = load i64, ptr @B, align 8, !tbaa !5
  %37 = icmp eq i64 %35, %36
  %38 = zext i1 %37 to i64
  %39 = mul nsw i64 %34, %38
  %40 = add nsw i64 %30, %39
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr %6, align 8, !tbaa !5
  %43 = add nsw i64 %42, 1
  %44 = load i64, ptr %7, align 8, !tbaa !5
  %45 = load i64, ptr @f, align 8, !tbaa !5
  %46 = mul nsw i64 %44, %45
  %47 = call noundef i64 @_Z1slll(i64 noundef %41, i64 noundef %43, i64 noundef %46)
  %48 = add nsw i64 %40, %47
  store i64 %48, ptr %4, align 8
  br label %49

49:                                               ; preds = %12, %11
  %50 = load i64, ptr %4, align 8
  ret i64 %50
}

attributes #0 = { 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" }

!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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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

@d = external dso_local local_unnamed_addr global i64, align 8
@B = external dso_local local_unnamed_addr global i64, align 8
@f = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z1slll(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i64 %2, %0
  br i1 %4, label %24, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %5 = load i64, ptr @f, align 8, !tbaa !5
  %6 = load i64, ptr @d, align 8, !tbaa !5
  br label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph, %tailrecurse
  %.tr1619 = phi i64 [ %2, %.lr.ph ], [ %19, %tailrecurse ]
  %.tr1518 = phi i64 [ %1, %.lr.ph ], [ %18, %tailrecurse ]
  %accumulator.tr17 = phi i64 [ 0, %.lr.ph ], [ %22, %tailrecurse ]
  %7 = sdiv i64 %0, %.tr1619
  %8 = srem i64 %7, 10
  %9 = sdiv i64 %.tr1619, %5
  %10 = mul i64 %8, %.tr1518
  %11 = mul i64 %10, %9
  %12 = icmp slt i64 %6, %8
  %13 = select i1 %12, i64 %.tr1619, i64 0
  %14 = srem i64 %0, %.tr1619
  %15 = add nsw i64 %14, 1
  %16 = icmp eq i64 %6, %8
  %17 = select i1 %16, i64 %15, i64 0
  %18 = add nsw i64 %.tr1518, 1
  %19 = mul nsw i64 %5, %.tr1619
  %20 = add i64 %11, %accumulator.tr17
  %21 = add i64 %20, %13
  %22 = add i64 %21, %17
  %23 = icmp sgt i64 %19, %0
  br i1 %23, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse
  store i64 %8, ptr @B, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %tailrecurse._crit_edge, %3
  %accumulator.tr.lcssa = phi i64 [ %22, %tailrecurse._crit_edge ], [ 0, %3 ]
  ret i64 %accumulator.tr.lcssa
}

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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass