; LLVM IR from tangjz/acm-icpc :: hdu/6711.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"

@tot = external dso_local global i32, align 4
@ptot = external dso_local global i32, align 4
@p = external dso_local global [9 x i32], align 16
@seq = external dso_local global [25600257 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 %3, align 4, !tbaa !5
  %6 = load i32, ptr @ptot, align 4, !tbaa !5
  %7 = icmp eq i32 %5, %6
  br i1 %7, label %8, label %14

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %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 [25600257 x i32], ptr @seq, i64 0, i64 %12
  store i32 %9, ptr %13, align 4, !tbaa !5
  br label %27

14:                                               ; preds = %2
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %16, i32 noundef %17)
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sub nsw i32 0, %20
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [9 x i32], ptr @p, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = mul nsw i32 %21, %25
  call void @_Z3dfsii(i32 noundef %19, i32 noundef %26)
  br label %27

27:                                               ; preds = %14, %8
  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"

@tot = external dso_local local_unnamed_addr global i32, align 4
@ptot = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [9 x i32], align 16
@seq = external dso_local local_unnamed_addr global [25600257 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 {
  %3 = load i32, ptr @ptot, align 4, !tbaa !5
  %4 = icmp eq i32 %3, %0
  br i1 %4, label %tailrecurse._crit_edge, label %tailrecurse.preheader

tailrecurse.preheader:                            ; preds = %2
  %5 = sext i32 %0 to i64
  br label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  %.tr7.lcssa = phi i32 [ %1, %2 ], [ %14, %tailrecurse ]
  %6 = load i32, ptr @tot, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @tot, align 4, !tbaa !5
  %8 = sext i32 %6 to i64
  %9 = getelementptr inbounds [25600257 x i32], ptr @seq, i64 0, i64 %8
  store i32 %.tr7.lcssa, ptr %9, align 4, !tbaa !5
  ret void

tailrecurse:                                      ; preds = %tailrecurse.preheader, %tailrecurse
  %indvars.iv = phi i64 [ %5, %tailrecurse.preheader ], [ %indvars.iv.next, %tailrecurse ]
  %.tr79 = phi i32 [ %1, %tailrecurse.preheader ], [ %14, %tailrecurse ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %10 = trunc nsw i64 %indvars.iv.next to i32
  tail call void @_Z3dfsii(i32 noundef %10, i32 noundef %.tr79)
  %11 = getelementptr inbounds [9 x i32], ptr @p, i64 0, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = mul i32 %.tr79, %12
  %14 = sub i32 0, %13
  %15 = load i32, ptr @ptot, align 4, !tbaa !5
  %16 = icmp eq i32 %15, %10
  br i1 %16, label %tailrecurse._crit_edge, label %tailrecurse
}

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,GVNPass,GlobalOptPass,IndVarSimplifyPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass