; LLVM IR from tangjz/acm-icpc :: lydsy (1089)

; 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, [60 x i32] }

@f = external dso_local global [17 x %struct.Node], align 16
@n = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 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 %struct.Node, align 4
  %5 = alloca %struct.Node, align 4
  %6 = alloca %struct.Node, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.Node, align 4
  %9 = alloca %struct.Node, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @d)
  call void @_ZN4Node4initEv(ptr noundef nonnull align 4 dereferenceable(244) @f)
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %46, %0
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr @d, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %15, label %49

15:                                               ; preds = %11
  %16 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %16, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 244, ptr %4) #6
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sub nsw i32 %17, 1
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %19
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %20, i64 244, i1 false), !tbaa.struct !9
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %22
  call void @_ZN4Node4initEv(ptr noundef nonnull align 4 dereferenceable(244) %23)
  br label %24

24:                                               ; preds = %39, %15
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %42

27:                                               ; preds = %24
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = and i32 %28, 1
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %35

31:                                               ; preds = %27
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %33
  call void @llvm.lifetime.start.p0(i64 244, ptr %5) #6
  call void @_ZN4NodemLERKS_(ptr dead_on_unwind writable sret(%struct.Node) align 4 %5, ptr noundef nonnull align 4 dereferenceable(244) %34, ptr noundef nonnull align 4 dereferenceable(244) %4)
  call void @llvm.lifetime.end.p0(i64 244, ptr %5) #6
  br label %35

35:                                               ; preds = %31, %27
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 1
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 244, ptr %6) #6
  call void @_ZN4NodemLERKS_(ptr dead_on_unwind writable sret(%struct.Node) align 4 %6, ptr noundef nonnull align 4 dereferenceable(244) %4, ptr noundef nonnull align 4 dereferenceable(244) %4)
  call void @llvm.lifetime.end.p0(i64 244, ptr %6) #6
  br label %39

39:                                               ; preds = %38, %35
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = ashr i32 %40, 1
  store i32 %41, ptr %3, align 4, !tbaa !5
  br label %24, !llvm.loop !11

42:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 1, ptr %7, align 4, !tbaa !5
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %44
  call void @llvm.lifetime.start.p0(i64 244, ptr %8) #6
  call void @_ZN4NodepLERKi(ptr dead_on_unwind writable sret(%struct.Node) align 4 %8, ptr noundef nonnull align 4 dereferenceable(244) %45, ptr noundef nonnull align 4 dereferenceable(4) %7)
  call void @llvm.lifetime.end.p0(i64 244, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 244, ptr %4) #6
  br label %46

46:                                               ; preds = %42
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !13

49:                                               ; preds = %11
  %50 = load i32, ptr @d, align 4, !tbaa !5
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %60

52:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 244, ptr %9) #6
  %53 = load i32, ptr @d, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %54
  %56 = load i32, ptr @d, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %58
  call void @_ZN4NodemiERKS_(ptr dead_on_unwind writable sret(%struct.Node) align 4 %9, ptr noundef nonnull align 4 dereferenceable(244) %55, ptr noundef nonnull align 4 dereferenceable(244) %59)
  call void @_ZN4Node5PrintEv(ptr noundef nonnull align 4 dereferenceable(244) %9)
  call void @llvm.lifetime.end.p0(i64 244, ptr %9) #6
  br label %64

60:                                               ; preds = %49
  %61 = load i32, ptr @d, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %62
  call void @_ZN4Node5PrintEv(ptr noundef nonnull align 4 dereferenceable(244) %63)
  br label %64

64:                                               ; preds = %60, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  ret i32 0
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Node4initEv(ptr noundef nonnull align 4 dereferenceable(244)) #3 align 2

; 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) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4NodemLERKS_(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4, ptr noundef nonnull align 4 dereferenceable(244), ptr noundef nonnull align 4 dereferenceable(244)) #5 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4NodepLERKi(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4, ptr noundef nonnull align 4 dereferenceable(244), ptr noundef nonnull align 4 dereferenceable(4)) #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodemiERKS_(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4, ptr noundef nonnull align 4 dereferenceable(244), ptr noundef nonnull align 4 dereferenceable(244)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Node5PrintEv(ptr noundef nonnull align 4 dereferenceable(244)) #5 align 2

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

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

@f = external dso_local global [17 x %struct.Node], align 16
@n = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.Node, align 4
  %2 = alloca %struct.Node, align 4
  %3 = alloca %struct.Node, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.Node, align 4
  %6 = alloca %struct.Node, align 4
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @d)
  tail call void @_ZN4Node4initEv(ptr noundef nonnull align 4 dereferenceable(244) @f)
  %8 = load i32, ptr @d, align 4, !tbaa !5
  %.not18 = icmp slt i32 %8, 1
  br i1 %.not18, label %._crit_edge22, label %.lr.ph21

.lr.ph21:                                         ; preds = %0, %._crit_edge
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 1, %0 ]
  %9 = load i32, ptr @n, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 244, ptr nonnull %1) #6
  %10 = add nsw i64 %indvars.iv, -1
  %11 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %10
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(244) %1, ptr noundef nonnull align 4 dereferenceable(244) %11, i64 244, i1 false), !tbaa.struct !9
  %12 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %indvars.iv
  call void @_ZN4Node4initEv(ptr noundef nonnull align 4 dereferenceable(244) %12)
  %.not1316 = icmp eq i32 %9, 0
  br i1 %.not1316, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph21, %16
  %.017 = phi i32 [ %17, %16 ], [ %9, %.lr.ph21 ]
  %13 = and i32 %.017, 1
  %.not14 = icmp eq i32 %13, 0
  br i1 %.not14, label %15, label %14

14:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 244, ptr nonnull %2) #6
  call void @_ZN4NodemLERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 4 %2, ptr noundef nonnull align 4 dereferenceable(244) %12, ptr noundef nonnull align 4 dereferenceable(244) %1)
  call void @llvm.lifetime.end.p0(i64 244, ptr nonnull %2) #6
  br label %15

15:                                               ; preds = %14, %.lr.ph
  %.not15 = icmp eq i32 %.017, 1
  br i1 %.not15, label %._crit_edge, label %16

16:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 244, ptr nonnull %3) #6
  call void @_ZN4NodemLERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 4 %3, ptr noundef nonnull align 4 dereferenceable(244) %1, ptr noundef nonnull align 4 dereferenceable(244) %1)
  call void @llvm.lifetime.end.p0(i64 244, ptr nonnull %3) #6
  %17 = ashr i32 %.017, 1
  %.not13 = icmp eq i32 %.017, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %15, %16, %.lr.ph21
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 244, ptr nonnull %5) #6
  call void @_ZN4NodepLERKi(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 4 %5, ptr noundef nonnull align 4 dereferenceable(244) %12, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @llvm.lifetime.end.p0(i64 244, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 244, ptr nonnull %1) #6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr @d, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %.not.not = icmp slt i64 %indvars.iv, %19
  br i1 %.not.not, label %.lr.ph21, label %._crit_edge22, !llvm.loop !13

._crit_edge22:                                    ; preds = %._crit_edge, %0
  %.lcssa = phi i32 [ %8, %0 ], [ %18, %._crit_edge ]
  %.not12 = icmp eq i32 %.lcssa, 0
  br i1 %.not12, label %26, label %20

20:                                               ; preds = %._crit_edge22
  call void @llvm.lifetime.start.p0(i64 244, ptr nonnull %6) #6
  %21 = sext i32 %.lcssa to i64
  %22 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %21
  %23 = add nsw i32 %.lcssa, -1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [17 x %struct.Node], ptr @f, i64 0, i64 %24
  call void @_ZN4NodemiERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 4 %6, ptr noundef nonnull align 4 dereferenceable(244) %22, ptr noundef nonnull align 4 dereferenceable(244) %25)
  call void @_ZN4Node5PrintEv(ptr noundef nonnull align 4 dereferenceable(244) %6)
  call void @llvm.lifetime.end.p0(i64 244, ptr nonnull %6) #6
  br label %27

26:                                               ; preds = %._crit_edge22
  call void @_ZN4Node5PrintEv(ptr noundef nonnull align 4 dereferenceable(244) @f)
  br label %27

27:                                               ; preds = %26, %20
  ret i32 0
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Node4initEv(ptr noundef nonnull align 4 dereferenceable(244)) local_unnamed_addr #3 align 2

; 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) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4NodemLERKS_(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4, ptr noundef nonnull align 4 dereferenceable(244), ptr noundef nonnull align 4 dereferenceable(244)) local_unnamed_addr #5 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4NodepLERKi(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4, ptr noundef nonnull align 4 dereferenceable(244), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodemiERKS_(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4, ptr noundef nonnull align 4 dereferenceable(244), ptr noundef nonnull align 4 dereferenceable(244)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Node5PrintEv(ptr noundef nonnull align 4 dereferenceable(244)) local_unnamed_addr #5 align 2

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


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