; LLVM IR from tangjz/acm-icpc :: codeforces/complete/300C.ll (Z3dfsii)

; 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 i32, align 4
@b = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@sum = external dso_local global [101 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = load i32, ptr @a, align 4, !tbaa !5
  %8 = mul nsw i32 %6, %7
  %9 = icmp sge i32 %5, %8
  br i1 %9, label %10, label %22

10:                                               ; preds = %2
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = load i32, ptr @b, align 4, !tbaa !5
  %14 = mul nsw i32 %12, %13
  %15 = icmp sle i32 %11, %14
  br i1 %15, label %16, label %22

16:                                               ; preds = %10
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr @tot, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @tot, align 4, !tbaa !5
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [101 x i32], ptr @sum, i64 0, i64 %20
  store i32 %17, ptr %21, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %16, %10, %2
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 7
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  br label %39

26:                                               ; preds = %22
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = mul nsw i32 %29, 10
  %31 = load i32, ptr @a, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  call void @_Z3dfsii(i32 noundef %28, i32 noundef %32)
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = mul nsw i32 %35, 10
  %37 = load i32, ptr @b, align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  call void @_Z3dfsii(i32 noundef %34, i32 noundef %38)
  br label %39

39:                                               ; preds = %26, %25
  ret void
}

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 = !{!"int", !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"

@a = external dso_local local_unnamed_addr global i32, align 4
@b = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@sum = external dso_local local_unnamed_addr global [101 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %16, %2
  %.tr = phi i32 [ %0, %2 ], [ %17, %16 ]
  %.tr10 = phi i32 [ %1, %2 ], [ %21, %16 ]
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = load i32, ptr @a, align 4, !tbaa !5
  %5 = mul nsw i32 %4, %3
  %.not = icmp sgt i32 %5, %.tr10
  br i1 %.not, label %14, label %6

6:                                                ; preds = %tailrecurse
  %7 = load i32, ptr @b, align 4, !tbaa !5
  %8 = mul nsw i32 %7, %3
  %.not9 = icmp slt i32 %8, %.tr10
  br i1 %.not9, label %14, label %9

9:                                                ; preds = %6
  %10 = load i32, ptr @tot, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @tot, align 4, !tbaa !5
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds [101 x i32], ptr @sum, i64 0, i64 %12
  store i32 %.tr10, ptr %13, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %9, %6, %tailrecurse
  %15 = icmp eq i32 %.tr, 7
  br i1 %15, label %22, label %16

16:                                               ; preds = %14
  %17 = add nsw i32 %.tr, 1
  %18 = mul nsw i32 %.tr10, 10
  %19 = add nsw i32 %4, %18
  tail call void @_Z3dfsii(i32 noundef %17, i32 noundef %19)
  %20 = load i32, ptr @b, align 4, !tbaa !5
  %21 = add nsw i32 %20, %18
  br label %tailrecurse

22:                                               ; preds = %14
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass