; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/字符串算法/模糊匹配.ll (Z3insRiiii)

; 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, i32, i32 }

@sz = external dso_local global i32, align 4
@T = external dso_local global [10250000 x %struct.node], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3insRiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = add nsw i32 %11, %12
  %14 = ashr i32 %13, 1
  store i32 %14, ptr %9, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %17
  %19 = load i32, ptr @sz, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @sz, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %21
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %22, ptr align 4 %18, i64 12, i1 false), !tbaa.struct !11
  %23 = load i32, ptr @sz, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %23, ptr %24, align 4, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 4, !tbaa !12
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %29, align 4, !tbaa !12
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %4
  store i32 1, ptr %10, align 4
  br label %60

36:                                               ; preds = %4
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = icmp sle i32 %37, %38
  br i1 %39, label %40, label %49

40:                                               ; preds = %36
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z3insRiiii(ptr noundef nonnull align 4 dereferenceable(4) %45, i32 noundef %46, i32 noundef %47, i32 noundef %48)
  br label %59

49:                                               ; preds = %36
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.node, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z3insRiiii(ptr noundef nonnull align 4 dereferenceable(4) %54, i32 noundef %56, i32 noundef %57, i32 noundef %58)
  br label %59

59:                                               ; preds = %49, %40
  store i32 0, ptr %10, align 4
  br label %60

60:                                               ; preds = %59, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %61 = load i32, ptr %10, align 4
  switch i32 %61, label %63 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  ret void

63:                                               ; preds = %60
  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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9}
!12 = !{!13, !10, i64 8}
!13 = !{!"_ZTS4node", !10, i64 0, !10, i64 4, !10, i64 8}


; 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, i32, i32 }

@sz = external dso_local local_unnamed_addr global i32, align 4
@T = external dso_local local_unnamed_addr global [10250000 x %struct.node], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z3insRiiii(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %23, %4
  %.tr.ph = phi ptr [ %24, %23 ], [ %0, %4 ]
  %.tr20.ph = phi i32 [ %25, %23 ], [ %1, %4 ]
  %.tr21.ph = phi i32 [ %.tr21, %23 ], [ %2, %4 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %21
  %.tr = phi ptr [ %22, %21 ], [ %.tr.ph, %tailrecurse.outer ]
  %.tr21 = phi i32 [ %6, %21 ], [ %.tr21.ph, %tailrecurse.outer ]
  %5 = add nsw i32 %.tr21, %.tr20.ph
  %6 = ashr i32 %5, 1
  %7 = load i32, ptr %.tr, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %8
  %10 = load i32, ptr @sz, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @sz, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %12
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %13, ptr noundef nonnull align 4 dereferenceable(12) %9, i64 12, i1 false), !tbaa.struct !9
  store i32 %11, ptr %.tr, align 4, !tbaa !5
  %14 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %12, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !10
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %14, align 4, !tbaa !10
  %17 = icmp eq i32 %.tr20.ph, %.tr21
  br i1 %17, label %26, label %18

18:                                               ; preds = %tailrecurse
  %.not = icmp slt i32 %6, %3
  %19 = load i32, ptr %.tr, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  br i1 %.not, label %23, label %21

21:                                               ; preds = %18
  %22 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %20
  br label %tailrecurse

23:                                               ; preds = %18
  %24 = getelementptr inbounds [10250000 x %struct.node], ptr @T, i64 0, i64 %20, i32 1
  %25 = add nsw i32 %6, 1
  br label %tailrecurse.outer

26:                                               ; preds = %tailrecurse
  ret void
}

; 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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 4, !5, i64 8, i64 4, !5}
!10 = !{!11, !6, i64 8}
!11 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass