; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 2/1119. Metro.ll (Z7dynamicv)

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

%struct.Point = type { i32, i32 }

@M = external dso_local global i32, align 4
@N = external dso_local global i32, align 4
@P = external dso_local global i32, align 4
@T = external dso_local global [1002 x %struct.Point], align 16
@F = external dso_local global [1002 x i32], align 16
@Ans = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [6 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 uwtable
define dso_local void @_Z7dynamicv() #1 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %75, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = load i32, ptr @P, align 4, !tbaa !5
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %10, label %78

10:                                               ; preds = %6
  store i32 0, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %55, %10
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  %15 = icmp sle i32 %12, %14
  br i1 %15, label %16, label %58

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1002 x %struct.Point], ptr @T, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.Point, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1002 x %struct.Point], ptr @T, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.Point, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = icmp slt i32 %21, %26
  br i1 %27, label %28, label %54

28:                                               ; preds = %16
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1002 x %struct.Point], ptr @T, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Point, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1002 x %struct.Point], ptr @T, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Point, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = icmp slt i32 %33, %38
  br i1 %39, label %40, label %54

40:                                               ; preds = %28
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1002 x i32], ptr @F, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = icmp sgt i32 %45, %46
  br i1 %47, label %48, label %54

48:                                               ; preds = %40
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1002 x i32], ptr @F, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %3, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %48, %40, %28, %16
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !12

58:                                               ; preds = %11
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = load i32, ptr %1, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1002 x i32], ptr @F, i64 0, i64 %61
  store i32 %59, ptr %62, align 4, !tbaa !5
  %63 = load i32, ptr %1, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1002 x i32], ptr @F, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = icmp sgt i32 %66, %67
  br i1 %68, label %69, label %74

69:                                               ; preds = %58
  %70 = load i32, ptr %1, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [1002 x i32], ptr @F, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  store i32 %73, ptr %4, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %69, %58
  br label %75

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

78:                                               ; preds = %6
  %79 = load i32, ptr @N, align 4, !tbaa !5
  %80 = load i32, ptr @M, align 4, !tbaa !5
  %81 = add nsw i32 %79, %80
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = mul nsw i32 %82, 2
  %84 = sub nsw i32 %81, %83
  %85 = sub nsw i32 %84, 2
  store i32 %85, ptr %5, align 4, !tbaa !5
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = sitofp i32 %86 to double
  %88 = load i32, ptr %4, align 4, !tbaa !5
  %89 = sitofp i32 %88 to double
  %90 = fmul double %89, 0x4061AD7BC01366B8
  %91 = call double @llvm.fmuladd.f64(double %87, double 1.000000e+02, double %90)
  store double %91, ptr @Ans, align 8, !tbaa !15
  %92 = load double, ptr @Ans, align 8, !tbaa !15
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %92)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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, !6, i64 0}
!10 = !{!"_ZTS5Point", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}


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

%struct.Point = type { i32, i32 }

@M = external dso_local local_unnamed_addr global i32, align 4
@N = external dso_local local_unnamed_addr global i32, align 4
@P = external dso_local local_unnamed_addr global i32, align 4
@T = external dso_local local_unnamed_addr global [1002 x %struct.Point], align 16
@F = external dso_local local_unnamed_addr global [1002 x i32], align 16
@Ans = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z7dynamicv() local_unnamed_addr #0 {
  %1 = load i32, ptr @P, align 4, !tbaa !5
  %.not30 = icmp slt i32 %1, 1
  br i1 %.not30, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %2 = add nuw i32 %1, 1
  %wide.trip.count38 = zext i32 %2 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.epilog-lcssa
  %indvar = phi i64 [ 0, %.preheader.preheader ], [ %indvar.next, %.epilog-lcssa ]
  %indvars.iv35 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next36, %.epilog-lcssa ]
  %.02031 = phi i32 [ 0, %.preheader.preheader ], [ %spec.select27, %.epilog-lcssa ]
  %3 = getelementptr inbounds [1002 x %struct.Point], ptr @T, i64 0, i64 %indvars.iv35
  %4 = load i32, ptr %3, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %3, i64 4
  %xtraiter = and i64 %indvars.iv35, 1
  %6 = icmp eq i64 %indvar, 0
  br i1 %6, label %.unr-lcssa, label %.preheader.new

.preheader.new:                                   ; preds = %.preheader
  %unroll_iter = and i64 %indvars.iv35, 9223372036854775806
  br label %7

7:                                                ; preds = %33, %.preheader.new
  %indvars.iv = phi i64 [ 0, %.preheader.new ], [ %indvars.iv.next.1, %33 ]
  %.02129 = phi i32 [ 0, %.preheader.new ], [ %.122.1, %33 ]
  %niter = phi i64 [ 0, %.preheader.new ], [ %niter.next.1, %33 ]
  %8 = getelementptr inbounds [1002 x %struct.Point], ptr @T, i64 0, i64 %indvars.iv
  %9 = load i32, ptr %8, align 16, !tbaa !9
  %10 = icmp slt i32 %9, %4
  br i1 %10, label %11, label %20

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %8, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = load i32, ptr %5, align 4, !tbaa !11
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %11
  %17 = getelementptr inbounds [1002 x i32], ptr @F, i64 0, i64 %indvars.iv
  %18 = load i32, ptr %17, align 8, !tbaa !5
  %.not26 = icmp slt i32 %18, %.02129
  %19 = add nsw i32 %18, 1
  %spec.select = select i1 %.not26, i32 %.02129, i32 %19
  br label %20

20:                                               ; preds = %16, %7, %11
  %.122 = phi i32 [ %.02129, %11 ], [ %.02129, %7 ], [ %spec.select, %16 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %21 = getelementptr inbounds [1002 x %struct.Point], ptr @T, i64 0, i64 %indvars.iv.next
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = icmp slt i32 %22, %4
  br i1 %23, label %24, label %33

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %21, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = load i32, ptr %5, align 4, !tbaa !11
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %24
  %30 = getelementptr inbounds [1002 x i32], ptr @F, i64 0, i64 %indvars.iv.next
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %.not26.1 = icmp slt i32 %31, %.122
  %32 = add nsw i32 %31, 1
  %spec.select.1 = select i1 %.not26.1, i32 %.122, i32 %32
  br label %33

33:                                               ; preds = %29, %24, %20
  %.122.1 = phi i32 [ %.122, %24 ], [ %.122, %20 ], [ %spec.select.1, %29 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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 %.unr-lcssa, label %7, !llvm.loop !12

.unr-lcssa:                                       ; preds = %33, %.preheader
  %.122.lcssa.ph = phi i32 [ poison, %.preheader ], [ %.122.1, %33 ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.1, %33 ]
  %.02129.unr = phi i32 [ 0, %.preheader ], [ %.122.1, %33 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.epilog-lcssa, label %.epil.preheader

.epil.preheader:                                  ; preds = %.unr-lcssa
  %34 = getelementptr inbounds [1002 x %struct.Point], ptr @T, i64 0, i64 %indvars.iv.unr
  %35 = load i32, ptr %34, align 8, !tbaa !9
  %36 = icmp slt i32 %35, %4
  br i1 %36, label %37, label %.epilog-lcssa

37:                                               ; preds = %.epil.preheader
  %38 = getelementptr inbounds i8, ptr %34, i64 4
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = load i32, ptr %5, align 4, !tbaa !11
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %.epilog-lcssa

42:                                               ; preds = %37
  %43 = getelementptr inbounds [1002 x i32], ptr @F, i64 0, i64 %indvars.iv.unr
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %.not26.epil = icmp slt i32 %44, %.02129.unr
  %45 = add nsw i32 %44, 1
  %spec.select.epil = select i1 %.not26.epil, i32 %.02129.unr, i32 %45
  br label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %.epil.preheader, %37, %42, %.unr-lcssa
  %.122.lcssa = phi i32 [ %.122.lcssa.ph, %.unr-lcssa ], [ %.02129.unr, %37 ], [ %.02129.unr, %.epil.preheader ], [ %spec.select.epil, %42 ]
  %46 = getelementptr inbounds [1002 x i32], ptr @F, i64 0, i64 %indvars.iv35
  store i32 %.122.lcssa, ptr %46, align 4, !tbaa !5
  %spec.select27 = tail call i32 @llvm.smax.i32(i32 %.122.lcssa, i32 %.02031)
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond39.not, label %._crit_edge, label %.preheader, !llvm.loop !14

._crit_edge:                                      ; preds = %.epilog-lcssa, %0
  %.020.lcssa = phi i32 [ 0, %0 ], [ %spec.select27, %.epilog-lcssa ]
  %47 = load i32, ptr @N, align 4, !tbaa !5
  %48 = load i32, ptr @M, align 4, !tbaa !5
  %49 = shl nuw i32 %.020.lcssa, 1
  %reass.sub = sub i32 %47, %49
  %50 = add i32 %reass.sub, -2
  %51 = add i32 %50, %48
  %52 = sitofp i32 %51 to double
  %53 = uitofp nneg i32 %.020.lcssa to double
  %54 = fmul double %53, 0x4061AD7BC01366B8
  %55 = tail call double @llvm.fmuladd.f64(double %52, double 1.000000e+02, double %54)
  store double %55, ptr @Ans, align 8, !tbaa !15
  %56 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %55)
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

attributes #0 = { mustprogress nofree 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !6, i64 0}
!10 = !{!"_ZTS5Point", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}


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