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

@n = external dso_local global i32, align 4
@sum = external dso_local global i32, align 4
@f = external dso_local global [1000001 x i32], align 16
@s = external dso_local global [1000001 x i32], align 16
@phi = external dso_local global [1000001 x i64], align 16
@ans = external dso_local global i64, align 8

; 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
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr @sum, align 4, !tbaa !5
  %8 = icmp sgt i32 %6, %7
  br i1 %8, label %9, label %21

9:                                                ; preds = %2
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sdiv i32 %12, %13
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1000001 x i64], ptr @phi, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = mul nsw i64 %11, %17
  %19 = load i64, ptr @ans, align 8, !tbaa !9
  %20 = add nsw i64 %19, %18
  store i64 %20, ptr @ans, align 8, !tbaa !9
  br label %45

21:                                               ; preds = %2
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  %24 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %23, i32 noundef %24)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %42, %21
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000001 x i32], ptr @s, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = icmp sle i32 %26, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %45

33:                                               ; preds = %25
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = mul nsw i32 %40, %39
  store i32 %41, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %35, i32 noundef %41)
  br label %42

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

45:                                               ; preds = %32, %9
  ret void
}

; 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 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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
@sum = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@s = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@phi = external dso_local local_unnamed_addr global [1000001 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8

; 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 @sum, align 4, !tbaa !5
  %4 = icmp slt i32 %3, %0
  br i1 %4, label %5, label %15

5:                                                ; preds = %2
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = sdiv i32 %6, %1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1000001 x i64], ptr @phi, i64 0, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = mul nsw i64 %11, %7
  %13 = load i64, ptr @ans, align 8, !tbaa !9
  %14 = add nsw i64 %13, %12
  store i64 %14, ptr @ans, align 8, !tbaa !9
  br label %.loopexit

15:                                               ; preds = %2
  %16 = add nsw i32 %0, 1
  tail call void @_Z3dfsii(i32 noundef %16, i32 noundef %1)
  %17 = sext i32 %0 to i64
  %18 = getelementptr inbounds [1000001 x i32], ptr @s, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not12 = icmp slt i32 %19, 1
  br i1 %.not12, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %15
  %20 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %17
  br label %21

21:                                               ; preds = %.lr.ph, %21
  %.014 = phi i32 [ 1, %.lr.ph ], [ %24, %21 ]
  %.01013 = phi i32 [ %1, %.lr.ph ], [ %23, %21 ]
  %22 = load i32, ptr %20, align 4, !tbaa !5
  %23 = mul nsw i32 %22, %.01013
  tail call void @_Z3dfsii(i32 noundef %16, i32 noundef %23)
  %24 = add nuw nsw i32 %.014, 1
  %25 = load i32, ptr %18, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.014, %25
  br i1 %.not.not, label %21, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %21, %15, %5
  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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass