; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SNACKDOWN/16/Elimination/Problem C (C)

; 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 [61 x i64], align 16
@C = external dso_local global [61 x [61 x i64]], align 16
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvev() #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

7:                                                ; preds = %24, %0
  %8 = load i32, ptr %2, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 61
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %27

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

24:                                               ; preds = %11
  %25 = load i32, ptr %2, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !9
  br label %7, !llvm.loop !11

27:                                               ; preds = %10
  store i64 1, ptr @C, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %78, %27
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = icmp slt i32 %29, 61
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %81

32:                                               ; preds = %28
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %34
  %36 = load i32, ptr %3, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [61 x i64], ptr %35, i64 0, i64 %37
  store i64 1, ptr %38, align 8, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %40
  %42 = getelementptr inbounds [61 x i64], ptr %41, i64 0, i64 0
  store i64 1, ptr %42, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %74, %32
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = load i32, ptr %3, align 4, !tbaa !9
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %48, label %47

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

48:                                               ; preds = %43
  %49 = load i32, ptr %3, align 4, !tbaa !9
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %51
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sub nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [61 x i64], ptr %52, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !9
  %59 = sub nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %60
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [61 x i64], ptr %61, i64 0, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !5
  %66 = add nsw i64 %57, %65
  %67 = srem i64 %66, 1000000007
  %68 = load i32, ptr %3, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %69
  %71 = load i32, ptr %5, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [61 x i64], ptr %70, i64 0, i64 %72
  store i64 %67, ptr %73, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %48
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %5, align 4, !tbaa !9
  br label %43, !llvm.loop !13

77:                                               ; preds = %47
  br label %78

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

81:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %82 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef %6)
  br label %83

83:                                               ; preds = %87, %81
  %84 = load i32, ptr %6, align 4, !tbaa !9
  %85 = add nsw i32 %84, -1
  store i32 %85, ptr %6, align 4, !tbaa !9
  %86 = icmp ne i32 %84, 0
  br i1 %86, label %87, label %88

87:                                               ; preds = %83
  call void @_Z5solvev()
  br label %83, !llvm.loop !15

88:                                               ; preds = %83
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %89 = load i32, ptr %1, align 4
  ret i32 %89
}

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 = { "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 #3 = { mustprogress norecurse 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 #4 = { 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}
!15 = distinct !{!15, !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 [61 x i64], align 16
@C = external dso_local local_unnamed_addr global [61 x [61 x i64]], align 16
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvev() local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  store i64 1, ptr @f, align 16, !tbaa !5
  br label %3

2:                                                ; preds = %3
  store i64 1, ptr @C, align 16, !tbaa !5
  br label %18

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

14:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull %1)
  %16 = load i32, ptr %1, align 4, !tbaa !11
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr %1, align 4, !tbaa !11
  %.not25 = icmp eq i32 %16, 0
  br i1 %.not25, label %._crit_edge28, label %.lr.ph27

18:                                               ; preds = %2, %._crit_edge
  %indvar = phi i64 [ 0, %2 ], [ %indvar.next, %._crit_edge ]
  %indvars.iv34 = phi i64 [ 1, %2 ], [ %indvars.iv.next35, %._crit_edge ]
  %19 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %indvars.iv34
  %20 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %indvars.iv34, i64 %indvars.iv34
  store i64 1, ptr %20, align 8, !tbaa !5
  store i64 1, ptr %19, align 8, !tbaa !5
  %21 = icmp ugt i64 %indvars.iv34, 1
  br i1 %21, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %18
  %22 = add nsw i64 %indvars.iv34, -1
  %.phi.trans.insert = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %22, i64 0
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !5
  %xtraiter = and i64 %indvar, 1
  %23 = icmp eq i64 %indvar, 1
  br i1 %23, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %indvar, -2
  br label %29

._crit_edge.loopexit.unr-lcssa:                   ; preds = %29, %.lr.ph
  %.unr = phi i64 [ %.pre, %.lr.ph ], [ %37, %29 ]
  %indvars.iv30.unr = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next31.1, %29 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %24 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %22, i64 %indvars.iv30.unr
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = add nsw i64 %25, %.unr
  %27 = srem i64 %26, 1000000007
  %28 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %indvars.iv34, i64 %indvars.iv30.unr
  store i64 %27, ptr %28, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %18
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next35, 61
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond37.not, label %14, label %18, !llvm.loop !13

29:                                               ; preds = %29, %.lr.ph.new
  %30 = phi i64 [ %.pre, %.lr.ph.new ], [ %37, %29 ]
  %indvars.iv30 = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next31.1, %29 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %29 ]
  %31 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %22, i64 %indvars.iv30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = add nsw i64 %32, %30
  %34 = srem i64 %33, 1000000007
  %35 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %indvars.iv34, i64 %indvars.iv30
  store i64 %34, ptr %35, align 8, !tbaa !5
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %36 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %22, i64 %indvars.iv.next31
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = add nsw i64 %37, %32
  %39 = srem i64 %38, 1000000007
  %40 = getelementptr inbounds [61 x [61 x i64]], ptr @C, i64 0, i64 %indvars.iv34, i64 %indvars.iv.next31
  store i64 %39, ptr %40, align 8, !tbaa !5
  %indvars.iv.next31.1 = add nuw nsw i64 %indvars.iv30, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %29, !llvm.loop !14

.lr.ph27:                                         ; preds = %14, %.lr.ph27
  call void @_Z5solvev()
  %41 = load i32, ptr %1, align 4, !tbaa !11
  %42 = add nsw i32 %41, -1
  store i32 %42, ptr %1, align 4, !tbaa !11
  %.not = icmp eq i32 %41, 0
  br i1 %.not, label %._crit_edge28, label %.lr.ph27, !llvm.loop !15

._crit_edge28:                                    ; preds = %.lr.ph27, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 #3 = { mustprogress norecurse 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 #4 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass