; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1063（字典树）.ll (Z6insertx)

; 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"

@ch = external dso_local global [550010 x [2 x i64]], align 16
@val = external dso_local global [550010 x i64], align 16
@sz = external dso_local global i32, align 4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

6:                                                ; preds = %51, %1
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp sge i32 %7, 0
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %54

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = ashr i64 %11, %13
  %15 = and i64 %14, 1
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %5, align 4, !tbaa !9
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [550010 x [2 x i64]], ptr @ch, i64 0, i64 %18
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2 x i64], ptr %19, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %42, label %25

25:                                               ; preds = %10
  %26 = load i32, ptr @sz, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [550010 x [2 x i64]], ptr @ch, i64 0, i64 %27
  %29 = getelementptr inbounds [2 x i64], ptr %28, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %29, i8 0, i64 16, i1 false)
  %30 = load i32, ptr @sz, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [550010 x i64], ptr @val, i64 0, i64 %31
  store i64 0, ptr %32, align 8, !tbaa !5
  %33 = load i32, ptr @sz, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @sz, align 4, !tbaa !9
  %35 = sext i32 %33 to i64
  %36 = load i32, ptr %3, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [550010 x [2 x i64]], ptr @ch, i64 0, i64 %37
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2 x i64], ptr %38, i64 0, i64 %40
  store i64 %35, ptr %41, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %25, %10
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [550010 x [2 x i64]], ptr @ch, i64 0, i64 %44
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2 x i64], ptr %45, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !5
  %50 = trunc i64 %49 to i32
  store i32 %50, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %51

51:                                               ; preds = %42
  %52 = load i32, ptr %4, align 4, !tbaa !9
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !11

54:                                               ; preds = %9
  %55 = load i64, ptr %2, align 8, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [550010 x i64], ptr @val, i64 0, i64 %57
  store i64 %55, ptr %58, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nosync 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@ch = external dso_local local_unnamed_addr global [550010 x [2 x i64]], align 16
@val = external dso_local local_unnamed_addr global [550010 x i64], align 16
@sz = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z6insertx(i64 noundef %0) local_unnamed_addr #1 {
  %sz.promoted = load i32, ptr @sz, align 4, !tbaa !5
  br label %5

2:                                                ; preds = %17
  %sext15 = shl i64 %18, 32
  %3 = ashr exact i64 %sext15, 32
  %4 = getelementptr inbounds [550010 x i64], ptr @val, i64 0, i64 %3
  store i64 %0, ptr %4, align 8, !tbaa !9
  ret void

5:                                                ; preds = %1, %17
  %indvars.iv = phi i64 [ 26, %1 ], [ %indvars.iv.next, %17 ]
  %.014 = phi i64 [ 0, %1 ], [ %18, %17 ]
  %6 = phi i32 [ %sz.promoted, %1 ], [ %19, %17 ]
  %7 = lshr i64 %0, %indvars.iv
  %8 = and i64 %7, 1
  %sext = shl i64 %.014, 32
  %9 = ashr exact i64 %sext, 32
  %10 = getelementptr inbounds [550010 x [2 x i64]], ptr @ch, i64 0, i64 %9, i64 %8
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %12, label %17

12:                                               ; preds = %5
  %13 = sext i32 %6 to i64
  %14 = getelementptr inbounds [550010 x [2 x i64]], ptr @ch, i64 0, i64 %13
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %14, i8 0, i64 16, i1 false)
  %15 = getelementptr inbounds [550010 x i64], ptr @val, i64 0, i64 %13
  store i64 0, ptr %15, align 8, !tbaa !9
  %16 = add nsw i32 %6, 1
  store i32 %16, ptr @sz, align 4, !tbaa !5
  store i64 %13, ptr %10, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %12, %5
  %18 = phi i64 [ %13, %12 ], [ %11, %5 ]
  %19 = phi i32 [ %16, %12 ], [ %6, %5 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not17 = icmp eq i64 %indvars.iv, 0
  br i1 %.not17, label %2, label %5, !llvm.loop !11
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nofree norecurse 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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