; LLVM IR from upupming/algorithm :: CCCC-GPLT/L3-015. 球队“食物链” (main)

; 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
@flag = external dso_local global i32, align 4
@result = external dso_local global [21 x i32], align 16
@v = external dso_local global [21 x [21 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1

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

; 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: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca [21 x i8], align 16
  %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)
  call void @llvm.lifetime.start.p0(i64 21, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %55, %0
  %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 %13, label %12

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

13:                                               ; preds = %8
  %14 = getelementptr inbounds [21 x i8], ptr %2, i64 0, i64 0
  %15 = getelementptr inbounds i8, ptr %14, i64 1
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %51, %13
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %54

22:                                               ; preds = %17
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [21 x i8], ptr %2, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 87
  br i1 %28, label %29, label %36

29:                                               ; preds = %22
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [21 x [21 x i8]], ptr @v, i64 0, i64 %31
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [21 x i8], ptr %32, i64 0, i64 %34
  store i8 1, ptr %35, align 1, !tbaa !10
  br label %36

36:                                               ; preds = %29, %22
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [21 x i8], ptr %2, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 %41, 76
  br i1 %42, label %43, label %50

43:                                               ; preds = %36
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [21 x [21 x i8]], ptr @v, i64 0, i64 %45
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [21 x i8], ptr %46, i64 0, i64 %48
  store i8 1, ptr %49, align 1, !tbaa !10
  br label %50

50:                                               ; preds = %43, %36
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %17, !llvm.loop !12

54:                                               ; preds = %21
  br label %55

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

58:                                               ; preds = %12
  call void @_Z3dfsii(i32 noundef 1, i32 noundef 1)
  %59 = load i32, ptr @flag, align 4, !tbaa !5
  %60 = icmp eq i32 %59, 1
  br i1 %60, label %61, label %81

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

62:                                               ; preds = %77, %61
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = load i32, ptr @n, align 4, !tbaa !5
  %65 = icmp sle i32 %63, %64
  br i1 %65, label %67, label %66

66:                                               ; preds = %62
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %80

67:                                               ; preds = %62
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = icmp eq i32 %68, 1
  %70 = zext i1 %69 to i64
  %71 = select i1 %69, ptr @.str.3, ptr @.str.4
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [21 x i32], ptr @result, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %71, i32 noundef %75)
  br label %77

77:                                               ; preds = %67
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %6, align 4, !tbaa !5
  br label %62, !llvm.loop !15

80:                                               ; preds = %66
  br label %83

81:                                               ; preds = %58
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %83

83:                                               ; preds = %81, %80
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 21, ptr %2) #4
  %84 = load i32, ptr %1, align 4
  ret i32 %84
}

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

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync 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 = { "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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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
@flag = external dso_local local_unnamed_addr global i32, align 4
@result = external dso_local local_unnamed_addr global [21 x i32], align 16
@v = external dso_local local_unnamed_addr global [21 x [21 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca [21 x i8], align 16
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  call void @llvm.lifetime.start.p0(i64 21, ptr nonnull %1) #4
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not21 = icmp slt i32 %3, 1
  br i1 %.not21, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %0
  %4 = getelementptr inbounds i8, ptr %1, i64 1
  br label %11

._crit_edge25:                                    ; preds = %._crit_edge, %0
  call void @_Z3dfsii(i32 noundef 1, i32 noundef 1)
  %5 = load i32, ptr @flag, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %.preheader, label %40

.preheader:                                       ; preds = %._crit_edge25
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %.not1726 = icmp slt i32 %7, 1
  br i1 %.not1726, label %.loopexit, label %.lr.ph28.preheader

.lr.ph28.preheader:                               ; preds = %.preheader
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @result, i64 4), align 4, !tbaa !5
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull @.str.3, i32 noundef %8)
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %.not17.not.peel = icmp sgt i32 %10, 1
  br i1 %.not17.not.peel, label %.lr.ph28, label %.loopexit

11:                                               ; preds = %.lr.ph24, %._crit_edge
  %indvars.iv30 = phi i64 [ 1, %.lr.ph24 ], [ %indvars.iv.next31, %._crit_edge ]
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %4)
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %.not1819 = icmp slt i32 %13, 1
  br i1 %.not1819, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %14 = zext nneg i32 %13 to i64
  %xtraiter = and i64 %14, 1
  %15 = icmp eq i32 %13, 1
  br i1 %15, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %14, 2147483646
  br label %22

._crit_edge.loopexit.unr-lcssa:                   ; preds = %34, %.lr.ph
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next.1, %34 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa
  %16 = getelementptr inbounds [21 x i8], ptr %1, i64 0, i64 %indvars.iv.unr
  %17 = load i8, ptr %16, align 1, !tbaa !9
  switch i8 %17, label %._crit_edge [
    i8 87, label %.thread.epil
    i8 76, label %18
  ]

18:                                               ; preds = %.epil.preheader
  %19 = getelementptr inbounds [21 x [21 x i8]], ptr @v, i64 0, i64 %indvars.iv.unr, i64 %indvars.iv30
  br label %.sink.split.epil

.thread.epil:                                     ; preds = %.epil.preheader
  %20 = getelementptr inbounds [21 x [21 x i8]], ptr @v, i64 0, i64 %indvars.iv30, i64 %indvars.iv.unr
  br label %.sink.split.epil

.sink.split.epil:                                 ; preds = %.thread.epil, %18
  %.sink.epil = phi ptr [ %20, %.thread.epil ], [ %19, %18 ]
  store i8 1, ptr %.sink.epil, align 1, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.sink.split.epil, %.epil.preheader, %11
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %21 = sext i32 %13 to i64
  %.not.not = icmp slt i64 %indvars.iv30, %21
  br i1 %.not.not, label %11, label %._crit_edge25, !llvm.loop !12

22:                                               ; preds = %34, %.lr.ph.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.1, %34 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %34 ]
  %23 = getelementptr inbounds [21 x i8], ptr %1, i64 0, i64 %indvars.iv
  %24 = load i8, ptr %23, align 1, !tbaa !9
  switch i8 %24, label %28 [
    i8 87, label %.thread
    i8 76, label %26
  ]

.thread:                                          ; preds = %22
  %25 = getelementptr inbounds [21 x [21 x i8]], ptr @v, i64 0, i64 %indvars.iv30, i64 %indvars.iv
  br label %.sink.split

26:                                               ; preds = %22
  %27 = getelementptr inbounds [21 x [21 x i8]], ptr @v, i64 0, i64 %indvars.iv, i64 %indvars.iv30
  br label %.sink.split

.sink.split:                                      ; preds = %26, %.thread
  %.sink = phi ptr [ %25, %.thread ], [ %27, %26 ]
  store i8 1, ptr %.sink, align 1, !tbaa !10
  br label %28

28:                                               ; preds = %.sink.split, %22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = getelementptr inbounds [21 x i8], ptr %1, i64 0, i64 %indvars.iv.next
  %30 = load i8, ptr %29, align 1, !tbaa !9
  switch i8 %30, label %34 [
    i8 87, label %.thread.1
    i8 76, label %31
  ]

31:                                               ; preds = %28
  %32 = getelementptr inbounds [21 x [21 x i8]], ptr @v, i64 0, i64 %indvars.iv.next, i64 %indvars.iv30
  br label %.sink.split.1

.thread.1:                                        ; preds = %28
  %33 = getelementptr inbounds [21 x [21 x i8]], ptr @v, i64 0, i64 %indvars.iv30, i64 %indvars.iv.next
  br label %.sink.split.1

.sink.split.1:                                    ; preds = %.thread.1, %31
  %.sink.1 = phi ptr [ %33, %.thread.1 ], [ %32, %31 ]
  store i8 1, ptr %.sink.1, align 1, !tbaa !10
  br label %34

34:                                               ; preds = %.sink.split.1, %28
  %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 %._crit_edge.loopexit.unr-lcssa, label %22, !llvm.loop !14

.lr.ph28:                                         ; preds = %.lr.ph28.preheader, %.lr.ph28
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %.lr.ph28 ], [ 2, %.lr.ph28.preheader ]
  %35 = getelementptr inbounds [21 x i32], ptr @result, i64 0, i64 %indvars.iv33
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull @.str.4, i32 noundef %36)
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %.not17.not = icmp slt i64 %indvars.iv33, %39
  br i1 %.not17.not, label %.lr.ph28, label %.loopexit, !llvm.loop !15

40:                                               ; preds = %._crit_edge25
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph28, %.lr.ph28.preheader, %.preheader, %40
  call void @llvm.lifetime.end.p0(i64 21, ptr nonnull %1) #4
  ret i32 0
}

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

; 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 nosync 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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13, !16}
!16 = !{!"llvm.loop.peeled.count", i32 1}


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