; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/369 Division 2/Problem D/D.ll (Z3dfsi)

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

@nxt = external dso_local global [200100 x i32], align 16
@vis = external dso_local global [200100 x i32], align 16
@ts = external dso_local global [200100 x i32], align 16
@tme = external dso_local global i32, align 4
@done = external dso_local global [200100 x i32], align 16
@tot = external dso_local global i32, align 4
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4fastxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [200100 x i32], ptr @vis, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %41

8:                                                ; preds = %1
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [200100 x i32], ptr @done, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %8
  br label %57

15:                                               ; preds = %8
  %16 = load i32, ptr @tme, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [200100 x i32], ptr @ts, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sub nsw i32 %16, %20
  %22 = add nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = call noundef i64 @_Z4fastxx(i64 noundef 2, i64 noundef %23)
  %25 = sub nsw i64 %24, 2
  %26 = add nsw i64 %25, 1000000007
  %27 = srem i64 %26, 1000000007
  %28 = load i64, ptr @ans, align 8, !tbaa !9
  %29 = mul nsw i64 %28, %27
  store i64 %29, ptr @ans, align 8, !tbaa !9
  %30 = load i64, ptr @ans, align 8, !tbaa !9
  %31 = srem i64 %30, 1000000007
  store i64 %31, ptr @ans, align 8, !tbaa !9
  %32 = load i32, ptr @tme, align 4, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [200100 x i32], ptr @ts, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sub nsw i32 %32, %36
  %38 = add nsw i32 %37, 1
  %39 = load i32, ptr @tot, align 4, !tbaa !5
  %40 = add nsw i32 %39, %38
  store i32 %40, ptr @tot, align 4, !tbaa !5
  br label %57

41:                                               ; preds = %1
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [200100 x i32], ptr @vis, i64 0, i64 %43
  store i32 1, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr @tme, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr @tme, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [200100 x i32], ptr @ts, i64 0, i64 %48
  store i32 %46, ptr %49, align 4, !tbaa !5
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [200100 x i32], ptr @nxt, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %53)
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [200100 x i32], ptr @done, i64 0, i64 %55
  store i32 1, ptr %56, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %41, %15, %14
  ret void
}

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 = { 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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

@nxt = external dso_local local_unnamed_addr global [200100 x i32], align 16
@vis = external dso_local local_unnamed_addr global [200100 x i32], align 16
@ts = external dso_local local_unnamed_addr global [200100 x i32], align 16
@tme = external dso_local local_unnamed_addr global i32, align 4
@done = external dso_local local_unnamed_addr global [200100 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4fastxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [200100 x i32], ptr @vis, i64 0, i64 %2
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %27, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds [200100 x i32], ptr @done, i64 0, i64 %2
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not8 = icmp eq i32 %7, 0
  br i1 %.not8, label %8, label %common.ret10

8:                                                ; preds = %5
  %9 = load i32, ptr @tme, align 4, !tbaa !5
  %10 = getelementptr inbounds [200100 x i32], ptr @ts, i64 0, i64 %2
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add i32 %9, 1
  %13 = sub i32 %12, %11
  %14 = sext i32 %13 to i64
  %15 = tail call noundef i64 @_Z4fastxx(i64 noundef 2, i64 noundef %14)
  %16 = add nsw i64 %15, 1000000005
  %17 = srem i64 %16, 1000000007
  %18 = load i64, ptr @ans, align 8, !tbaa !9
  %19 = mul nsw i64 %17, %18
  %20 = srem i64 %19, 1000000007
  store i64 %20, ptr @ans, align 8, !tbaa !9
  %21 = load i32, ptr @tme, align 4, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = load i32, ptr @tot, align 4, !tbaa !5
  %24 = add i32 %21, 1
  %25 = sub i32 %24, %22
  %26 = add nsw i32 %25, %23
  store i32 %26, ptr @tot, align 4, !tbaa !5
  br label %common.ret10

common.ret10:                                     ; preds = %5, %8, %27
  ret void

27:                                               ; preds = %1
  store i32 1, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr @tme, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @tme, align 4, !tbaa !5
  %30 = getelementptr inbounds [200100 x i32], ptr @ts, i64 0, i64 %2
  store i32 %29, ptr %30, align 4, !tbaa !5
  %31 = getelementptr inbounds [200100 x i32], ptr @nxt, i64 0, i64 %2
  %32 = load i32, ptr %31, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %32)
  %33 = getelementptr inbounds [200100 x i32], ptr @done, i64 0, i64 %2
  store i32 1, ptr %33, align 4, !tbaa !5
  br label %common.ret10
}

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

!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}


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