; LLVM IR from tangjz/acm-icpc :: codeforces/complete (924B)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@fz = external dso_local global i32, align 4
@fm = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %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
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %18, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr @a, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %16)
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

21:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %22 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %22, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %23 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %23, ptr %4, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %91, %21
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = icmp sge i32 %25, 1
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %94

28:                                               ; preds = %24
  br label %29

29:                                               ; preds = %87, %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = icmp sgt i32 %30, 1
  br i1 %31, label %32, label %45

32:                                               ; preds = %29
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sub nsw i32 %36, %41
  %43 = load i32, ptr @m, align 4, !tbaa !5
  %44 = icmp sle i32 %42, %43
  br label %45

45:                                               ; preds = %32, %29
  %46 = phi i1 [ false, %29 ], [ %44, %32 ]
  br i1 %46, label %47, label %90

47:                                               ; preds = %45
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %86

51:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = sub nsw i32 %55, %59
  store i32 %60, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sub nsw i32 %65, 1
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = sub nsw i32 %64, %69
  store i32 %70, ptr %6, align 4, !tbaa !5
  %71 = load i32, ptr @fz, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = mul nsw i64 %72, %74
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = load i32, ptr @fm, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = mul nsw i64 %77, %79
  %81 = icmp slt i64 %75, %80
  br i1 %81, label %82, label %85

82:                                               ; preds = %51
  %83 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %83, ptr @fz, align 4, !tbaa !5
  %84 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %84, ptr @fm, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %82, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %86

86:                                               ; preds = %85, %47
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %4, align 4, !tbaa !5
  %89 = add nsw i32 %88, -1
  store i32 %89, ptr %4, align 4, !tbaa !5
  br label %29, !llvm.loop !11

90:                                               ; preds = %45
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr %3, align 4, !tbaa !5
  br label %24, !llvm.loop !12

94:                                               ; preds = %27
  %95 = load i32, ptr @fz, align 4, !tbaa !5
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %104

97:                                               ; preds = %94
  %98 = load i32, ptr @fz, align 4, !tbaa !5
  %99 = sitofp i32 %98 to double
  %100 = load i32, ptr @fm, align 4, !tbaa !5
  %101 = sitofp i32 %100 to double
  %102 = fdiv double %99, %101
  %103 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %102)
  br label %106

104:                                              ; preds = %94
  %105 = call i32 @puts(ptr noundef @.str.3)
  br label %106

106:                                              ; preds = %104, %97
  ret i32 0
}

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

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

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

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

declare i32 @puts(ptr noundef) #1

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


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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [100001 x i32], align 16
@fz = external dso_local local_unnamed_addr global i32, align 4
@fm = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not28 = icmp slt i32 %2, 1
  br i1 %.not28, label %.preheader27.._crit_edge_crit_edge, label %.lr.ph

.preheader27:                                     ; preds = %.lr.ph
  %3 = icmp sgt i32 %8, 0
  br i1 %3, label %.preheader.lr.ph, label %.preheader27.._crit_edge_crit_edge

.preheader27.._crit_edge_crit_edge:               ; preds = %0, %.preheader27
  %.pre = load i32, ptr @fz, align 4, !tbaa !5
  br label %._crit_edge

.preheader.lr.ph:                                 ; preds = %.preheader27
  %fm.promoted40 = load i32, ptr @fm, align 4, !tbaa !5
  %fz.promoted35 = load i32, ptr @fz, align 4, !tbaa !5
  %4 = load i32, ptr @m, align 4
  %5 = zext nneg i32 %8 to i64
  br label %.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %6 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %.not.not = icmp slt i64 %indvars.iv, %9
  br i1 %.not.not, label %.lr.ph, label %.preheader27, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.lr.ph, %.critedge
  %indvars.iv56 = phi i64 [ %5, %.preheader.lr.ph ], [ %indvars.iv.next57, %.critedge ]
  %.02149 = phi i32 [ %8, %.preheader.lr.ph ], [ %.1.lcssa, %.critedge ]
  %fz.promoted3948 = phi i32 [ %fz.promoted35, %.preheader.lr.ph ], [ %fz.promoted36, %.critedge ]
  %fm.promoted4447 = phi i32 [ %fm.promoted40, %.preheader.lr.ph ], [ %fm.promoted41, %.critedge ]
  %10 = icmp sgt i32 %.02149, 1
  br i1 %10, label %.lr.ph31, label %.critedge

.lr.ph31:                                         ; preds = %.preheader
  %11 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv56
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = zext nneg i32 %.02149 to i64
  br label %15

._crit_edge:                                      ; preds = %.critedge, %.preheader27.._crit_edge_crit_edge
  %14 = phi i32 [ %.pre, %.preheader27.._crit_edge_crit_edge ], [ %fz.promoted36, %.critedge ]
  %.not25 = icmp eq i32 %14, 0
  br i1 %.not25, label %47, label %41

15:                                               ; preds = %.lr.ph31, %35
  %indvars.iv53 = phi i64 [ %13, %.lr.ph31 ], [ %indvars.iv.next54, %35 ]
  %fm.promoted43 = phi i32 [ %fm.promoted4447, %.lr.ph31 ], [ %fm.promoted42, %35 ]
  %fz.promoted38 = phi i32 [ %fz.promoted3948, %.lr.ph31 ], [ %fz.promoted37, %35 ]
  %16 = phi i32 [ %fz.promoted3948, %.lr.ph31 ], [ %37, %35 ]
  %17 = phi i32 [ %fm.promoted4447, %.lr.ph31 ], [ %36, %35 ]
  %indvars.iv.next54 = add nsw i64 %indvars.iv53, -1
  %18 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv.next54
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sub nsw i32 %12, %19
  %.not26 = icmp sgt i32 %20, %4
  br i1 %.not26, label %.critedge.loopexit.split.loop.exit, label %21

21:                                               ; preds = %15
  %22 = icmp slt i64 %indvars.iv53, %indvars.iv56
  br i1 %22, label %23, label %35

23:                                               ; preds = %21
  %24 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %indvars.iv53
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sub nsw i32 %12, %25
  %27 = sext i32 %16 to i64
  %28 = sext i32 %20 to i64
  %29 = mul nsw i64 %27, %28
  %30 = sext i32 %26 to i64
  %31 = sext i32 %17 to i64
  %32 = mul nsw i64 %31, %30
  %33 = icmp slt i64 %29, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %23
  store i32 %26, ptr @fz, align 4, !tbaa !5
  store i32 %20, ptr @fm, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %23, %34, %21
  %fm.promoted42 = phi i32 [ %fm.promoted43, %23 ], [ %20, %34 ], [ %fm.promoted43, %21 ]
  %fz.promoted37 = phi i32 [ %fz.promoted38, %23 ], [ %26, %34 ], [ %fz.promoted38, %21 ]
  %36 = phi i32 [ %17, %23 ], [ %20, %34 ], [ %17, %21 ]
  %37 = phi i32 [ %16, %23 ], [ %26, %34 ], [ %16, %21 ]
  %38 = icmp ugt i64 %indvars.iv53, 2
  br i1 %38, label %15, label %.critedge, !llvm.loop !11

.critedge.loopexit.split.loop.exit:               ; preds = %15
  %39 = trunc nuw nsw i64 %indvars.iv53 to i32
  br label %.critedge

.critedge:                                        ; preds = %35, %.critedge.loopexit.split.loop.exit, %.preheader
  %fm.promoted41 = phi i32 [ %fm.promoted4447, %.preheader ], [ %fm.promoted43, %.critedge.loopexit.split.loop.exit ], [ %fm.promoted42, %35 ]
  %fz.promoted36 = phi i32 [ %fz.promoted3948, %.preheader ], [ %fz.promoted38, %.critedge.loopexit.split.loop.exit ], [ %fz.promoted37, %35 ]
  %.1.lcssa = phi i32 [ %.02149, %.preheader ], [ %39, %.critedge.loopexit.split.loop.exit ], [ 1, %35 ]
  %indvars.iv.next57 = add nsw i64 %indvars.iv56, -1
  %40 = icmp sgt i64 %indvars.iv56, 1
  br i1 %40, label %.preheader, label %._crit_edge, !llvm.loop !12

41:                                               ; preds = %._crit_edge
  %42 = sitofp i32 %14 to double
  %43 = load i32, ptr @fm, align 4, !tbaa !5
  %44 = sitofp i32 %43 to double
  %45 = fdiv double %42, %44
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %45)
  br label %49

47:                                               ; preds = %._crit_edge
  %48 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %49

49:                                               ; preds = %47, %41
  ret i32 0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

attributes #0 = { mustprogress nofree norecurse 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 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass