; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p3386.ll (Z4findi)

; 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.edge = type { i32, i32 }

@e = external dso_local global [50010 x %struct.edge], align 16
@head = external dso_local global [550 x i32], align 16
@vis = external dso_local global [550 x i8], align 16
@matched = external dso_local global [550 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z4findi(i32 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [550 x i32], ptr @head, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %10, ptr %4, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %51, %1
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %5, align 4
  br label %57

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [50010 x %struct.edge], ptr @e, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.edge, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !9
  store i32 %20, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [550 x i8], ptr @vis, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !11, !range !13, !noundef !14
  %25 = trunc i8 %24 to i1
  br i1 %25, label %47, label %26

26:                                               ; preds = %15
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [550 x i8], ptr @vis, i64 0, i64 %28
  store i8 1, ptr %29, align 1, !tbaa !11
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [550 x i32], ptr @matched, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %41

35:                                               ; preds = %26
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [550 x i32], ptr @matched, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = call noundef zeroext i1 @_Z4findi(i32 noundef %39)
  br i1 %40, label %41, label %46

41:                                               ; preds = %35, %26
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [550 x i32], ptr @matched, i64 0, i64 %44
  store i32 %42, ptr %45, align 4, !tbaa !5
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %48

46:                                               ; preds = %35
  br label %47

47:                                               ; preds = %46, %15
  store i32 0, ptr %5, align 4
  br label %48

48:                                               ; preds = %47, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %49 = load i32, ptr %5, align 4
  switch i32 %49, label %57 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [50010 x %struct.edge], ptr @e, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.edge, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !15
  store i32 %56, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !16

57:                                               ; preds = %48, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %58 = load i32, ptr %5, align 4
  switch i32 %58, label %62 [
    i32 2, label %59
    i32 1, label %60
  ]

59:                                               ; preds = %57
  store i1 false, ptr %2, align 1
  br label %60

60:                                               ; preds = %59, %57
  %61 = load i1, ptr %2, align 1
  ret i1 %61

62:                                               ; preds = %57
  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

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


; 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.edge = type { i32, i32 }

@e = external dso_local local_unnamed_addr global [50010 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [550 x i32], align 16
@vis = external dso_local local_unnamed_addr global [550 x i8], align 16
@matched = external dso_local local_unnamed_addr global [550 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z4findi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [550 x i32], ptr @head, i64 0, i64 %2
  %.01420 = load i32, ptr %3, align 4, !tbaa !5
  %.not21.not = icmp eq i32 %.01420, 0
  br i1 %.not21.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %17
  %.01422 = phi i32 [ %.014, %17 ], [ %.01420, %1 ]
  %4 = sext i32 %.01422 to i64
  %5 = getelementptr inbounds [50010 x %struct.edge], ptr @e, i64 0, i64 %4
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [550 x i8], ptr @vis, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %17, label %11

11:                                               ; preds = %.lr.ph
  store i8 1, ptr %8, align 1, !tbaa !11
  %12 = getelementptr inbounds [550 x i32], ptr @matched, i64 0, i64 %7
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not16 = icmp eq i32 %13, 0
  br i1 %.not16, label %.critedge, label %14

14:                                               ; preds = %11
  %15 = tail call noundef zeroext i1 @_Z4findi(i32 noundef %13)
  br i1 %15, label %.critedge, label %17

.critedge:                                        ; preds = %14, %11
  %16 = getelementptr inbounds [550 x i32], ptr @matched, i64 0, i64 %7
  store i32 %0, ptr %16, align 4, !tbaa !5
  br label %.loopexit

17:                                               ; preds = %14, %.lr.ph
  %18 = getelementptr inbounds i8, ptr %5, i64 4
  %.014 = load i32, ptr %18, align 4, !tbaa !5
  %.not.not = icmp eq i32 %.014, 0
  br i1 %.not.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %17, %1, %.critedge
  %.not18 = phi i1 [ true, %.critedge ], [ false, %1 ], [ false, %17 ]
  ret i1 %.not18
}

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


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