; LLVM IR from lzyrapx/Competitive-Programming :: BZOJ/BZOJ1061（对偶原则+单纯形）.ll (Z7simplexv)

; 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 [10005 x [1005 x double]], align 16
@b = external dso_local global [10005 x double], align 16
@c = external dso_local global [10005 x double], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z7simplexv() #0 {
  %1 = alloca double, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  br label %7

7:                                                ; preds = %87, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store double 1.000000e+09, ptr %4, align 8, !tbaa !9
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %20, %7
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr @N, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %12, label %23

12:                                               ; preds = %8
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [10005 x double], ptr @c, i64 0, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = fcmp ogt double %16, 0x3EB0C6F7A0B5ED8D
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  br label %23

19:                                               ; preds = %12
  br label %20

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

23:                                               ; preds = %18, %8
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = load i32, ptr @N, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = icmp eq i32 %24, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %23
  %29 = load double, ptr @a, align 16, !tbaa !9
  store double %29, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %85

30:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %75, %30
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr @M, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %36, label %35

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

36:                                               ; preds = %31
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [10005 x [1005 x double]], ptr @a, i64 0, i64 %38
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1005 x double], ptr %39, i64 0, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !9
  %44 = fcmp ogt double %43, 0x3EB0C6F7A0B5ED8D
  br i1 %44, label %45, label %74

45:                                               ; preds = %36
  %46 = load double, ptr %4, align 8, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [10005 x double], ptr @b, i64 0, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10005 x [1005 x double]], ptr @a, i64 0, i64 %52
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1005 x double], ptr %53, i64 0, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !9
  %58 = fdiv double %50, %57
  %59 = fcmp ogt double %46, %58
  br i1 %59, label %60, label %74

60:                                               ; preds = %45
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [10005 x double], ptr @b, i64 0, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !9
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [10005 x [1005 x double]], ptr @a, i64 0, i64 %66
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1005 x double], ptr %67, i64 0, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !9
  %72 = fdiv double %64, %71
  store double %72, ptr %4, align 8, !tbaa !9
  %73 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %73, ptr %2, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %60, %45, %36
  br label %75

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

78:                                               ; preds = %35
  %79 = load double, ptr %4, align 8, !tbaa !9
  %80 = fcmp oeq double %79, 1.000000e+09
  br i1 %80, label %81, label %82

81:                                               ; preds = %78
  store double 1.000000e+09, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %85

82:                                               ; preds = %78
  %83 = load i32, ptr %2, align 4, !tbaa !5
  %84 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z5pivotii(i32 noundef %83, i32 noundef %84)
  store i32 0, ptr %5, align 4
  br label %85

85:                                               ; preds = %82, %81, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %86 = load i32, ptr %5, align 4
  switch i32 %86, label %90 [
    i32 0, label %87
    i32 1, label %88
  ]

87:                                               ; preds = %85
  br label %7, !llvm.loop !14

88:                                               ; preds = %85
  %89 = load double, ptr %1, align 8
  ret double %89

90:                                               ; preds = %85
  unreachable
}

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z5pivotii(i32 noundef, i32 noundef) #2

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 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"double", !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"

@N = external dso_local local_unnamed_addr global i32, align 4
@M = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [10005 x [1005 x double]], align 16
@b = external dso_local local_unnamed_addr global [10005 x double], align 16
@c = external dso_local local_unnamed_addr global [10005 x double], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z7simplexv() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %48, %0
  %2 = load i32, ptr @N, align 4, !tbaa !5
  %.not34 = icmp slt i32 %2, 1
  %.pre = add i32 %2, 1
  br i1 %.not34, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = zext i32 %.pre to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %6
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %6 ]
  %3 = getelementptr inbounds [10005 x double], ptr @c, i64 0, i64 %indvars.iv
  %4 = load double, ptr %3, align 8, !tbaa !9
  %5 = fcmp ogt double %4, 0x3EB0C6F7A0B5ED8D
  br i1 %5, label %._crit_edge.loopexit, label %6

6:                                                ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.thread, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %7 = trunc nuw nsw i64 %indvars.iv to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %1, %._crit_edge.loopexit
  %.022.lcssa = phi i32 [ %7, %._crit_edge.loopexit ], [ 1, %1 ]
  %8 = icmp eq i32 %.022.lcssa, %.pre
  br i1 %8, label %._crit_edge.thread, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %9 = load i32, ptr @M, align 4, !tbaa !5
  %.not2940 = icmp slt i32 %9, 1
  br i1 %.not2940, label %.loopexit, label %.lr.ph44

.lr.ph44:                                         ; preds = %.preheader
  %10 = zext nneg i32 %.022.lcssa to i64
  %11 = zext nneg i32 %9 to i64
  %xtraiter = and i64 %11, 1
  %12 = icmp eq i32 %9, 1
  br i1 %12, label %._crit_edge45.unr-lcssa, label %.lr.ph44.new

.lr.ph44.new:                                     ; preds = %.lr.ph44
  %unroll_iter = and i64 %11, 2147483646
  br label %25

._crit_edge.thread:                               ; preds = %._crit_edge, %6
  %13 = load double, ptr @a, align 16, !tbaa !9
  br label %.loopexit

._crit_edge45.unr-lcssa:                          ; preds = %47, %.lr.ph44
  %.124.lcssa.ph = phi i32 [ poison, %.lr.ph44 ], [ %.124.1, %47 ]
  %.1.lcssa.ph = phi double [ poison, %.lr.ph44 ], [ %.1.1, %47 ]
  %indvars.iv49.unr = phi i64 [ 1, %.lr.ph44 ], [ %indvars.iv.next50.1, %47 ]
  %.02142.unr = phi double [ 1.000000e+09, %.lr.ph44 ], [ %.1.1, %47 ]
  %.02341.unr = phi i32 [ 0, %.lr.ph44 ], [ %.124.1, %47 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge45, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge45.unr-lcssa
  %14 = getelementptr inbounds [10005 x [1005 x double]], ptr @a, i64 0, i64 %indvars.iv49.unr, i64 %10
  %15 = load double, ptr %14, align 8, !tbaa !9
  %16 = fcmp ogt double %15, 0x3EB0C6F7A0B5ED8D
  br i1 %16, label %17, label %._crit_edge45

17:                                               ; preds = %.epil.preheader
  %18 = getelementptr inbounds [10005 x double], ptr @b, i64 0, i64 %indvars.iv49.unr
  %19 = load double, ptr %18, align 8, !tbaa !9
  %20 = fdiv double %19, %15
  %21 = fcmp ogt double %.02142.unr, %20
  br i1 %21, label %22, label %._crit_edge45

22:                                               ; preds = %17
  %23 = trunc nuw nsw i64 %indvars.iv49.unr to i32
  br label %._crit_edge45

._crit_edge45:                                    ; preds = %.epil.preheader, %17, %22, %._crit_edge45.unr-lcssa
  %.124.lcssa = phi i32 [ %.124.lcssa.ph, %._crit_edge45.unr-lcssa ], [ %23, %22 ], [ %.02341.unr, %17 ], [ %.02341.unr, %.epil.preheader ]
  %.1.lcssa = phi double [ %.1.lcssa.ph, %._crit_edge45.unr-lcssa ], [ %20, %22 ], [ %.02142.unr, %17 ], [ %.02142.unr, %.epil.preheader ]
  %24 = fcmp oeq double %.1.lcssa, 1.000000e+09
  br i1 %24, label %.loopexit, label %48

25:                                               ; preds = %47, %.lr.ph44.new
  %indvars.iv49 = phi i64 [ 1, %.lr.ph44.new ], [ %indvars.iv.next50.1, %47 ]
  %.02142 = phi double [ 1.000000e+09, %.lr.ph44.new ], [ %.1.1, %47 ]
  %.02341 = phi i32 [ 0, %.lr.ph44.new ], [ %.124.1, %47 ]
  %niter = phi i64 [ 0, %.lr.ph44.new ], [ %niter.next.1, %47 ]
  %26 = getelementptr inbounds [10005 x [1005 x double]], ptr @a, i64 0, i64 %indvars.iv49, i64 %10
  %27 = load double, ptr %26, align 8, !tbaa !9
  %28 = fcmp ogt double %27, 0x3EB0C6F7A0B5ED8D
  br i1 %28, label %29, label %36

29:                                               ; preds = %25
  %30 = getelementptr inbounds [10005 x double], ptr @b, i64 0, i64 %indvars.iv49
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = fdiv double %31, %27
  %33 = fcmp ogt double %.02142, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %29
  %35 = trunc nuw nsw i64 %indvars.iv49 to i32
  br label %36

36:                                               ; preds = %25, %29, %34
  %.124 = phi i32 [ %35, %34 ], [ %.02341, %29 ], [ %.02341, %25 ]
  %.1 = phi double [ %32, %34 ], [ %.02142, %29 ], [ %.02142, %25 ]
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %37 = getelementptr inbounds [10005 x [1005 x double]], ptr @a, i64 0, i64 %indvars.iv.next50, i64 %10
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = fcmp ogt double %38, 0x3EB0C6F7A0B5ED8D
  br i1 %39, label %40, label %47

40:                                               ; preds = %36
  %41 = getelementptr inbounds [10005 x double], ptr @b, i64 0, i64 %indvars.iv.next50
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = fdiv double %42, %38
  %44 = fcmp ogt double %.1, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %40
  %46 = trunc nuw nsw i64 %indvars.iv.next50 to i32
  br label %47

47:                                               ; preds = %45, %40, %36
  %.124.1 = phi i32 [ %46, %45 ], [ %.124, %40 ], [ %.124, %36 ]
  %.1.1 = phi double [ %43, %45 ], [ %.1, %40 ], [ %.1, %36 ]
  %indvars.iv.next50.1 = add nuw nsw i64 %indvars.iv49, 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_edge45.unr-lcssa, label %25, !llvm.loop !13

48:                                               ; preds = %._crit_edge45
  tail call void @_Z5pivotii(i32 noundef %.124.lcssa, i32 noundef %.022.lcssa)
  br label %1

.loopexit:                                        ; preds = %.preheader, %._crit_edge45, %._crit_edge.thread
  %.126.ph = phi double [ %13, %._crit_edge.thread ], [ 1.000000e+09, %._crit_edge45 ], [ 1.000000e+09, %.preheader ]
  ret double %.126.ph
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z5pivotii(i32 noundef, i32 noundef) local_unnamed_addr #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 = { 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" }

!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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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