; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/IPC/IPC15FLA/ASYAPATH/D.ll (Z3prev)

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

@f = external dso_local global [200100 x i64], align 16
@invf = external dso_local global [200100 x i64], align 16

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

; 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3prev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i64 1, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 1, ptr %1, align 4, !tbaa !9
  br label %3

3:                                                ; preds = %20, %0
  %4 = load i32, ptr %1, align 4, !tbaa !9
  %5 = icmp slt i32 %4, 200100
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %23

7:                                                ; preds = %3
  %8 = load i32, ptr %1, align 4, !tbaa !9
  %9 = sub nsw i32 %8, 1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [200100 x i64], ptr @f, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = load i32, ptr %1, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = mul nsw i64 %12, %14
  %16 = srem i64 %15, 1000000007
  %17 = load i32, ptr %1, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [200100 x i64], ptr @f, i64 0, i64 %18
  store i64 %16, ptr %19, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %7
  %21 = load i32, ptr %1, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %1, align 4, !tbaa !9
  br label %3, !llvm.loop !11

23:                                               ; preds = %6
  %24 = load i64, ptr getelementptr inbounds ([200100 x i64], ptr @f, i64 0, i64 200099), align 8, !tbaa !5
  %25 = call noundef i64 @_Z4fastxx(i64 noundef %24, i64 noundef 1000000005)
  store i64 %25, ptr getelementptr inbounds ([200100 x i64], ptr @invf, i64 0, i64 200099), align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 200098, ptr %2, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %44, %23
  %27 = load i32, ptr %2, align 4, !tbaa !9
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %47

30:                                               ; preds = %26
  %31 = load i32, ptr %2, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [200100 x i64], ptr @invf, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = load i32, ptr %2, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %35, %38
  %40 = srem i64 %39, 1000000007
  %41 = load i32, ptr %2, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [200100 x i64], ptr @invf, i64 0, i64 %42
  store i64 %40, ptr %43, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %30
  %45 = load i32, ptr %2, align 4, !tbaa !9
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %2, align 4, !tbaa !9
  br label %26, !llvm.loop !13

47:                                               ; preds = %29
  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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@f = external dso_local local_unnamed_addr global [200100 x i64], align 16
@invf = external dso_local local_unnamed_addr global [200100 x i64], align 16

; 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 @_Z3prev() local_unnamed_addr #0 {
  store i64 1, ptr @f, align 16, !tbaa !5
  br label %4

1:                                                ; preds = %4
  %2 = load i64, ptr getelementptr inbounds (i8, ptr @f, i64 1600792), align 8, !tbaa !5
  %3 = tail call noundef i64 @_Z4fastxx(i64 noundef %2, i64 noundef 1000000005)
  store i64 %3, ptr getelementptr inbounds (i8, ptr @invf, i64 1600792), align 8, !tbaa !5
  br label %14

4:                                                ; preds = %9, %0
  %5 = phi i64 [ 1, %0 ], [ %11, %9 ]
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next.1, %9 ]
  %6 = mul nsw i64 %5, %indvars.iv
  %7 = srem i64 %6, 1000000007
  %8 = getelementptr inbounds [200100 x i64], ptr @f, i64 0, i64 %indvars.iv
  store i64 %7, ptr %8, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 200100
  br i1 %exitcond.not, label %1, label %9, !llvm.loop !9

9:                                                ; preds = %4
  %10 = mul nsw i64 %7, %indvars.iv.next
  %11 = srem i64 %10, 1000000007
  %12 = getelementptr inbounds [200100 x i64], ptr @f, i64 0, i64 %indvars.iv.next
  store i64 %11, ptr %12, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  br label %4

13:                                               ; preds = %14
  ret void

14:                                               ; preds = %20, %1
  %15 = phi i64 [ %3, %1 ], [ %22, %20 ]
  %indvars.iv14 = phi i64 [ 200098, %1 ], [ %indvars.iv.next15.1, %20 ]
  %16 = or disjoint i64 %indvars.iv14, 1
  %17 = mul nsw i64 %15, %16
  %18 = srem i64 %17, 1000000007
  %19 = getelementptr inbounds [200100 x i64], ptr @invf, i64 0, i64 %indvars.iv14
  store i64 %18, ptr %19, align 16, !tbaa !5
  %.not = icmp eq i64 %indvars.iv14, 0
  br i1 %.not, label %13, label %20, !llvm.loop !11

20:                                               ; preds = %14
  %indvars.iv.next15 = add nsw i64 %indvars.iv14, -1
  %21 = mul nsw i64 %18, %indvars.iv14
  %22 = srem i64 %21, 1000000007
  %23 = getelementptr inbounds [200100 x i64], ptr @invf, i64 0, i64 %indvars.iv.next15
  store i64 %22, ptr %23, align 8, !tbaa !5
  %indvars.iv.next15.1 = add nsw i64 %indvars.iv14, -2
  br label %14
}

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass