; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/WF/Easy Medium/CNTWAYS/A.ll (Z5solvev)

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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z1Cii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %1, ptr noundef %2)
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3, ptr noundef %4)
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = add nsw i32 %13, %14
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = call noundef i64 @_Z1Cii(i32 noundef %15, i32 noundef %16)
  store i64 %17, ptr %5, align 8, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = add nsw i32 %18, %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sub nsw i32 %20, %21
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = call noundef i64 @_Z1Cii(i32 noundef %22, i32 noundef %23)
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sub nsw i32 %25, %26
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = add nsw i32 %27, %28
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = call noundef i64 @_Z1Cii(i32 noundef %29, i32 noundef %30)
  %32 = mul nsw i64 %24, %31
  %33 = srem i64 %32, 1000000007
  call void @_Z3subRxx(ptr noundef nonnull align 8 dereferenceable(8) %5, i64 noundef %33)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  store i32 %35, ptr %6, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %67, %0
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = icmp sge i32 %37, 0
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %70

40:                                               ; preds = %36
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = add nsw i32 %41, %42
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sub nsw i32 %43, %44
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = call noundef i64 @_Z1Cii(i32 noundef %45, i32 noundef %46)
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = sub nsw i32 %48, %49
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = add nsw i32 %50, %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = call noundef i64 @_Z1Cii(i32 noundef %52, i32 noundef %53)
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = sub nsw i32 %55, %56
  %58 = sub nsw i32 %57, 1
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = add nsw i32 %58, %59
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = call noundef i64 @_Z1Cii(i32 noundef %60, i32 noundef %61)
  %63 = sub nsw i64 %54, %62
  %64 = add nsw i64 %63, 1000000007
  %65 = mul nsw i64 %47, %64
  %66 = srem i64 %65, 1000000007
  call void @_Z3subRxx(ptr noundef nonnull align 8 dereferenceable(8) %5, i64 noundef %66)
  br label %67

67:                                               ; preds = %40
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = add nsw i32 %68, -1
  store i32 %69, ptr %6, align 4, !tbaa !5
  br label %36, !llvm.loop !11

70:                                               ; preds = %39
  %71 = load i64, ptr %5, align 8, !tbaa !9
  %72 = trunc i64 %71 to i32
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %72)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z3subRxx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #4

declare i32 @printf(ptr noundef, ...) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { "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 = { inlinehint 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 #5 = { 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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z1Cii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = add nsw i32 %13, %12
  %15 = call noundef i64 @_Z1Cii(i32 noundef %14, i32 noundef %12)
  store i64 %15, ptr %5, align 8, !tbaa !9
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = add nsw i32 %17, %16
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sub i32 %18, %19
  %21 = call noundef i64 @_Z1Cii(i32 noundef %20, i32 noundef %16)
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sub i32 %22, %23
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add nsw i32 %24, %25
  %27 = call noundef i64 @_Z1Cii(i32 noundef %26, i32 noundef %25)
  %28 = mul nsw i64 %27, %21
  %29 = srem i64 %28, 1000000007
  call void @_Z3subRxx(ptr noundef nonnull align 8 dereferenceable(8) %5, i64 noundef %29)
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = trunc i64 %32 to i32
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %33)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret void

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.0.in9 = phi i32 [ %.0, %.lr.ph ], [ %30, %0 ]
  %.0 = add nsw i32 %.0.in9, -1
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = add nsw i32 %35, %.0
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sub i32 %36, %37
  %39 = call noundef i64 @_Z1Cii(i32 noundef %38, i32 noundef %.0)
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %reass.sub = sub i32 %40, %.0.in9
  %41 = add i32 %reass.sub, 1
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = add nsw i32 %41, %42
  %44 = call noundef i64 @_Z1Cii(i32 noundef %43, i32 noundef %42)
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sub i32 %45, %.0.in9
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %46, %47
  %49 = call noundef i64 @_Z1Cii(i32 noundef %48, i32 noundef %47)
  %50 = add i64 %44, 1000000007
  %51 = sub i64 %50, %49
  %52 = mul nsw i64 %51, %39
  %53 = srem i64 %52, 1000000007
  call void @_Z3subRxx(ptr noundef nonnull align 8 dereferenceable(8) %5, i64 noundef %53)
  %54 = icmp ugt i32 %.0.in9, 1
  br i1 %54, label %.lr.ph, label %._crit_edge, !llvm.loop !11
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z3subRxx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { inlinehint 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 #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 = !{!"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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass