; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/IPC/IPC15P1A/Problem F/F.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"

@dp = external dso_local global [301 x [100100 x i64]], align 16
@f = external dso_local global [301 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3prev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i64 1, ptr @dp, 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 %5

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

8:                                                ; preds = %5
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %59

9:                                                ; preds = %5
  %10 = load i32, ptr %1, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [301 x [100100 x i64]], ptr @dp, i64 0, i64 %11
  %13 = getelementptr inbounds [100100 x i64], ptr %12, i64 0, i64 0
  store i64 1, ptr %13, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %52, %9
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 100100
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %55

18:                                               ; preds = %14
  %19 = load i32, ptr %1, align 4, !tbaa !9
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [301 x [100100 x i64]], ptr @dp, i64 0, i64 %21
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100100 x i64], ptr %22, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = load i32, ptr %1, align 4, !tbaa !9
  %29 = sub nsw i32 %27, %28
  %30 = icmp sge i32 %29, 0
  br i1 %30, label %31, label %41

31:                                               ; preds = %18
  %32 = load i32, ptr %1, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [301 x [100100 x i64]], ptr @dp, i64 0, i64 %33
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = load i32, ptr %1, align 4, !tbaa !9
  %37 = sub nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100100 x i64], ptr %34, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !5
  br label %42

41:                                               ; preds = %18
  br label %42

42:                                               ; preds = %41, %31
  %43 = phi i64 [ %40, %31 ], [ 0, %41 ]
  %44 = add nsw i64 %26, %43
  %45 = srem i64 %44, 1000000007
  %46 = load i32, ptr %1, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [301 x [100100 x i64]], ptr @dp, i64 0, i64 %47
  %49 = load i32, ptr %3, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100100 x i64], ptr %48, i64 0, i64 %50
  store i64 %45, ptr %51, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %42
  %53 = load i32, ptr %3, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %3, align 4, !tbaa !9
  br label %14, !llvm.loop !11

55:                                               ; preds = %17
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %1, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %1, align 4, !tbaa !9
  br label %5, !llvm.loop !13

59:                                               ; preds = %8
  store i64 1, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %77, %59
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = icmp slt i32 %61, 301
  br i1 %62, label %64, label %63

63:                                               ; preds = %60
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %80

64:                                               ; preds = %60
  %65 = load i32, ptr %4, align 4, !tbaa !9
  %66 = sub nsw i32 %65, 1
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [301 x i64], ptr @f, i64 0, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !5
  %70 = load i32, ptr %4, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = mul nsw i64 %69, %71
  %73 = srem i64 %72, 1000000007
  %74 = load i32, ptr %4, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [301 x i64], ptr @f, i64 0, i64 %75
  store i64 %73, ptr %76, align 8, !tbaa !5
  br label %77

77:                                               ; preds = %64
  %78 = load i32, ptr %4, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !9
  br label %60, !llvm.loop !14

80:                                               ; preds = %63
  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 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}
!14 = distinct !{!14, !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"

@dp = external dso_local local_unnamed_addr global [301 x [100100 x i64]], align 16
@f = external dso_local local_unnamed_addr global [301 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3prev() local_unnamed_addr #0 {
  store i64 1, ptr @dp, align 16, !tbaa !5
  br label %2

1:                                                ; preds = %5
  store i64 1, ptr @f, align 16, !tbaa !5
  br label %20

2:                                                ; preds = %0, %5
  %indvars.iv26 = phi i64 [ 1, %0 ], [ %indvars.iv.next27, %5 ]
  %3 = getelementptr inbounds [301 x [100100 x i64]], ptr @dp, i64 0, i64 %indvars.iv26
  store i64 1, ptr %3, align 16, !tbaa !5
  %4 = add nsw i64 %indvars.iv26, -1
  br label %6

5:                                                ; preds = %14
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next27, 301
  br i1 %exitcond29.not, label %1, label %2, !llvm.loop !9

6:                                                ; preds = %2, %14
  %indvars.iv = phi i64 [ 1, %2 ], [ %indvars.iv.next, %14 ]
  %7 = getelementptr inbounds [301 x [100100 x i64]], ptr @dp, i64 0, i64 %4, i64 %indvars.iv
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = sub nsw i64 %indvars.iv, %indvars.iv26
  %10 = icmp sgt i64 %9, -1
  br i1 %10, label %11, label %14

11:                                               ; preds = %6
  %12 = getelementptr inbounds [301 x [100100 x i64]], ptr @dp, i64 0, i64 %indvars.iv26, i64 %9
  %13 = load i64, ptr %12, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %6, %11
  %15 = phi i64 [ %13, %11 ], [ 0, %6 ]
  %16 = add nsw i64 %15, %8
  %17 = srem i64 %16, 1000000007
  %18 = getelementptr inbounds [301 x [100100 x i64]], ptr @dp, i64 0, i64 %indvars.iv26, i64 %indvars.iv
  store i64 %17, ptr %18, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100100
  br i1 %exitcond.not, label %5, label %6, !llvm.loop !11

19:                                               ; preds = %20
  ret void

20:                                               ; preds = %20, %1
  %21 = phi i64 [ 1, %1 ], [ %29, %20 ]
  %indvars.iv30 = phi i64 [ 1, %1 ], [ %indvars.iv.next31.2, %20 ]
  %22 = mul nsw i64 %21, %indvars.iv30
  %23 = srem i64 %22, 1000000007
  %24 = getelementptr inbounds [301 x i64], ptr @f, i64 0, i64 %indvars.iv30
  store i64 %23, ptr %24, align 8, !tbaa !5
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %25 = mul nsw i64 %23, %indvars.iv.next31
  %26 = srem i64 %25, 1000000007
  %27 = getelementptr inbounds [301 x i64], ptr @f, i64 0, i64 %indvars.iv.next31
  store i64 %26, ptr %27, align 8, !tbaa !5
  %indvars.iv.next31.1 = add nuw nsw i64 %indvars.iv30, 2
  %28 = mul nsw i64 %26, %indvars.iv.next31.1
  %29 = srem i64 %28, 1000000007
  %30 = getelementptr inbounds [301 x i64], ptr @f, i64 0, i64 %indvars.iv.next31.1
  store i64 %29, ptr %30, align 8, !tbaa !5
  %indvars.iv.next31.2 = add nuw nsw i64 %indvars.iv30, 3
  %exitcond33.not.2 = icmp eq i64 %indvars.iv.next31.2, 301
  br i1 %exitcond33.not.2, label %19, label %20, !llvm.loop !12
}

attributes #0 = { mustprogress nofree norecurse 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 = !{!"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}
!12 = distinct !{!12, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass