; LLVM IR from tangjz/acm-icpc :: codeforces/gym (100959G)

; 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.Node = type { i32, [5 x i32], [5 x i32] }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [5 x i32], align 16
@tot = external dso_local global i32, align 4
@inv = external dso_local global [11 x i32], align 16
@seq = external dso_local global [100001 x %struct.Node], align 16
@.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 [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3pfsii(i32 noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3dfsi4Node(i32 noundef, ptr noundef byval(%struct.Node) align 8) #0

; 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 %struct.Node, align 8
  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) #6
  store i32 0, 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 @m, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  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 @_Z3pfsii(i32 noundef 0, i32 noundef -1)
  %22 = load i32, ptr @tot, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds %struct.Node, ptr @seq, i64 %23
  call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef @seq, ptr noundef %24)
  %25 = load i32, ptr @tot, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.Node, ptr @seq, i64 %26
  %28 = call noundef ptr @_ZSt6uniqueIP4NodeET_S2_S2_(ptr noundef @seq, ptr noundef %27)
  %29 = ptrtoint ptr %28 to i64
  %30 = sub i64 %29, ptrtoint (ptr @seq to i64)
  %31 = sdiv exact i64 %30, 44
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr @tot, align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([11 x i32], ptr @inv, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %56, %21
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = load i32, ptr @m, align 4, !tbaa !5
  %36 = shl i32 %35, 1
  %37 = icmp sle i32 %34, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %59

39:                                               ; preds = %33
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sdiv i32 1000000007, %40
  %42 = sext i32 %41 to i64
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = srem i32 1000000007, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [11 x i32], ptr @inv, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = mul nsw i64 %42, %48
  %50 = srem i64 %49, 1000000007
  %51 = trunc i64 %50 to i32
  %52 = sub nsw i32 1000000007, %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [11 x i32], ptr @inv, i64 0, i64 %54
  store i32 %52, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %39
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %3, align 4, !tbaa !5
  br label %33, !llvm.loop !11

59:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %78, %59
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr @tot, align 4, !tbaa !5
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %65, label %64

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

65:                                               ; preds = %60
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [100001 x %struct.Node], ptr @seq, i64 0, i64 %68
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %69, i64 44, i1 false), !tbaa.struct !12
  %70 = call noundef i32 @_Z3dfsi4Node(i32 noundef %66, ptr noundef byval(%struct.Node) align 8 %6)
  %71 = load i32, ptr %4, align 4, !tbaa !5
  %72 = add nsw i32 %71, %70
  store i32 %72, ptr %4, align 4, !tbaa !5
  %73 = icmp sge i32 %72, 1000000007
  br i1 %73, label %74, label %77

74:                                               ; preds = %65
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sub nsw i32 %75, 1000000007
  store i32 %76, ptr %4, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %74, %65
  br label %78

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

81:                                               ; preds = %64
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %82)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef, ptr noundef) #5

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIP4NodeET_S2_S2_(ptr noundef, ptr noundef) #5

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

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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { inlinehint 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 #6 = { 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 = !{i64 0, i64 4, !5, i64 4, i64 20, !13, i64 24, i64 20, !13}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !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"

%struct.Node = type { i32, [5 x i32], [5 x i32] }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [5 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@inv = external dso_local local_unnamed_addr global [11 x i32], align 16
@seq = external dso_local global [100001 x %struct.Node], align 16
@.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 [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3pfsii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3dfsi4Node(i32 noundef, ptr noundef byval(%struct.Node) align 8) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca %struct.Node, align 8
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  tail call void @_Z3pfsii(i32 noundef 0, i32 noundef -1)
  %5 = load i32, ptr @tot, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds %struct.Node, ptr @seq, i64 %6
  tail call void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef nonnull @seq, ptr noundef nonnull %7)
  %8 = load i32, ptr @tot, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds %struct.Node, ptr @seq, i64 %9
  %11 = tail call noundef ptr @_ZSt6uniqueIP4NodeET_S2_S2_(ptr noundef nonnull @seq, ptr noundef nonnull %10)
  %12 = ptrtoint ptr %11 to i64
  %13 = sub i64 %12, ptrtoint (ptr @seq to i64)
  %14 = sdiv exact i64 %13, 44
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr @tot, align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = shl i32 %16, 1
  %.not21 = icmp slt i32 %17, 2
  br i1 %.not21, label %.preheader, label %.lr.ph24.preheader

.lr.ph24.preheader:                               ; preds = %._crit_edge
  %18 = or disjoint i32 %17, 1
  %wide.trip.count = zext nneg i32 %18 to i64
  br label %.lr.ph24

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %19 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %20 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %19)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr @m, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph24, %._crit_edge
  %24 = icmp sgt i32 %15, 0
  br i1 %24, label %.lr.ph27, label %._crit_edge28

.lr.ph24:                                         ; preds = %.lr.ph24.preheader, %.lr.ph24
  %indvars.iv30 = phi i64 [ 2, %.lr.ph24.preheader ], [ %indvars.iv.next31, %.lr.ph24 ]
  %25 = trunc nuw nsw i64 %indvars.iv30 to i32
  %26 = udiv i32 1000000007, %25
  %27 = zext nneg i32 %26 to i64
  %28 = urem i32 1000000007, %25
  %29 = zext nneg i32 %28 to i64
  %30 = getelementptr inbounds [11 x i32], ptr @inv, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = mul nsw i64 %32, %27
  %34 = srem i64 %33, 1000000007
  %35 = trunc nsw i64 %34 to i32
  %36 = sub nsw i32 1000000007, %35
  %37 = getelementptr inbounds [11 x i32], ptr @inv, i64 0, i64 %indvars.iv30
  store i32 %36, ptr %37, align 4, !tbaa !5
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph24, !llvm.loop !11

._crit_edge28:                                    ; preds = %.lr.ph27, %.preheader
  %.015.lcssa = phi i32 [ 0, %.preheader ], [ %spec.select, %.lr.ph27 ]
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.015.lcssa)
  ret i32 0

.lr.ph27:                                         ; preds = %.preheader, %.lr.ph27
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %.lr.ph27 ], [ 0, %.preheader ]
  %.01525 = phi i32 [ %spec.select, %.lr.ph27 ], [ 0, %.preheader ]
  %39 = getelementptr inbounds [100001 x %struct.Node], ptr @seq, i64 0, i64 %indvars.iv33
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(44) %1, ptr noundef nonnull align 4 dereferenceable(44) %39, i64 44, i1 false), !tbaa.struct !12
  %40 = trunc nuw nsw i64 %indvars.iv33 to i32
  %41 = tail call noundef i32 @_Z3dfsi4Node(i32 noundef %40, ptr noundef nonnull byval(%struct.Node) align 8 %1)
  %42 = add nsw i32 %41, %.01525
  %43 = icmp sgt i32 %42, 1000000006
  %44 = add nsw i32 %42, -1000000007
  %spec.select = select i1 %43, i32 %44, i32 %42
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %45 = load i32, ptr @tot, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = icmp slt i64 %indvars.iv.next34, %46
  br i1 %47, label %.lr.ph27, label %._crit_edge28, !llvm.loop !14
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP4NodeEvT_S2_(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIP4NodeET_S2_S2_(ptr noundef, ptr noundef) local_unnamed_addr #4

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

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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { inlinehint 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" }

!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 = !{i64 0, i64 4, !5, i64 4, i64 20, !13, i64 24, i64 20, !13}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !10}


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