; LLVM IR from lzyrapx/Competitive-Programming :: hihocoder/1036(tire树).ll (Z11node_insertPc)

; 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.TreeNode = type { [26 x i32], i32, i8 }

@node_cnt = external dso_local global i32, align 4
@node = external dso_local global [1000000 x %struct.TreeNode], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z11node_insertPc(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %49, %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %7, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %52

13:                                               ; preds = %6
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = sub nsw i32 %19, 97
  store i32 %20, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1000000 x %struct.TreeNode], ptr @node, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.TreeNode, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [26 x i32], ptr %24, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %40, label %30

30:                                               ; preds = %13
  %31 = load i32, ptr @node_cnt, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr @node_cnt, align 4, !tbaa !9
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000000 x %struct.TreeNode], ptr @node, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.TreeNode, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [26 x i32], ptr %36, i64 0, i64 %38
  store i32 %32, ptr %39, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %30, %13
  %41 = load i32, ptr %3, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000000 x %struct.TreeNode], ptr @node, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.TreeNode, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [26 x i32], ptr %44, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  store i32 %48, ptr %3, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %40
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !12

52:                                               ; preds = %6
  %53 = load i32, ptr %3, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1000000 x %struct.TreeNode], ptr @node, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.TreeNode, ptr %55, i32 0, i32 2
  store i8 1, ptr %56, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !16, i64 108}
!15 = !{!"_ZTS8TreeNode", !7, i64 0, !10, i64 104, !16, i64 108}
!16 = !{!"bool", !7, i64 0}


; 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.TreeNode = type { [26 x i32], i32, i8 }

@node_cnt = external dso_local local_unnamed_addr global i32, align 4
@node = external dso_local local_unnamed_addr global [1000000 x %struct.TreeNode], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @_Z11node_insertPc(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %.not14 = icmp eq i8 %2, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %node_cnt.promoted = load i32, ptr @node_cnt, align 4, !tbaa !8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %13 ]
  %3 = phi i8 [ %2, %.lr.ph.preheader ], [ %17, %13 ]
  %.016 = phi i32 [ 0, %.lr.ph.preheader ], [ %14, %13 ]
  %4 = phi i32 [ %node_cnt.promoted, %.lr.ph.preheader ], [ %15, %13 ]
  %5 = sext i8 %3 to i64
  %6 = add nsw i64 %5, -97
  %7 = sext i32 %.016 to i64
  %8 = getelementptr inbounds [1000000 x %struct.TreeNode], ptr @node, i64 0, i64 %7
  %9 = getelementptr inbounds [26 x i32], ptr %8, i64 0, i64 %6
  %10 = load i32, ptr %9, align 4, !tbaa !8
  %.not13 = icmp eq i32 %10, 0
  br i1 %.not13, label %11, label %13

11:                                               ; preds = %.lr.ph
  %12 = add nsw i32 %4, 1
  store i32 %12, ptr @node_cnt, align 4, !tbaa !8
  store i32 %12, ptr %9, align 4, !tbaa !8
  br label %13

13:                                               ; preds = %11, %.lr.ph
  %14 = phi i32 [ %12, %11 ], [ %10, %.lr.ph ]
  %15 = phi i32 [ %12, %11 ], [ %4, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %.not = icmp eq i8 %17, 0
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !10

._crit_edge.loopexit:                             ; preds = %13
  %18 = sext i32 %14 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.0.lcssa = phi i64 [ 0, %1 ], [ %18, %._crit_edge.loopexit ]
  %19 = getelementptr inbounds [1000000 x %struct.TreeNode], ptr @node, i64 0, i64 %.0.lcssa, i32 2
  store i8 1, ptr %19, align 4, !tbaa !12
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !14, i64 108}
!13 = !{!"_ZTS8TreeNode", !6, i64 0, !9, i64 104, !14, i64 108}
!14 = !{!"bool", !6, i64 0}


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