; LLVM IR from CZWin32768/ACMICPC-Templates-in-Latex :: atl/codes/Tree/LvTrie.ll (Z6inserti)

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

@chd = external dso_local global [32000160 x [2 x i32]], align 16
@nn = external dso_local global i32, align 4
@num = external dso_local global [32000160 x i32], align 16

; 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 @_Z6inserti(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 31, ptr %4, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %48, %1
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %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 %51

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = ashr i32 %11, %12
  %14 = and i32 %13, 1
  store i32 %14, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [32000160 x [2 x i32]], ptr @chd, i64 0, i64 %16
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2 x i32], ptr %17, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %40

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

40:                                               ; preds = %23, %10
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [32000160 x [2 x i32]], ptr @chd, i64 0, i64 %42
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [2 x i32], ptr %43, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  store i32 %47, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %48

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

51:                                               ; preds = %9
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [32000160 x i32], ptr @num, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %54, align 4, !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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@chd = external dso_local local_unnamed_addr global [32000160 x [2 x i32]], align 16
@nn = external dso_local local_unnamed_addr global i32, align 4
@num = external dso_local local_unnamed_addr global [32000160 x i32], align 16

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

2:                                                ; preds = %21
  %3 = sext i32 %22 to i64
  %4 = getelementptr inbounds [32000160 x i32], ptr @num, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr %4, align 4, !tbaa !5
  ret void

7:                                                ; preds = %1, %21
  %.013 = phi i32 [ 0, %1 ], [ %22, %21 ]
  %.01112 = phi i32 [ 31, %1 ], [ %24, %21 ]
  %8 = phi i32 [ %nn.promoted, %1 ], [ %23, %21 ]
  %9 = lshr i32 %0, %.01112
  %10 = and i32 %9, 1
  %11 = sext i32 %.013 to i64
  %12 = zext nneg i32 %10 to i64
  %13 = getelementptr inbounds [32000160 x [2 x i32]], ptr @chd, i64 0, i64 %11, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp eq i32 %14, -1
  br i1 %15, label %16, label %21

16:                                               ; preds = %7
  store i32 %8, ptr %13, align 4, !tbaa !5
  %17 = sext i32 %8 to i64
  %18 = getelementptr inbounds [32000160 x [2 x i32]], ptr @chd, i64 0, i64 %17
  store i64 -1, ptr %18, align 8
  %19 = getelementptr inbounds [32000160 x i32], ptr @num, i64 0, i64 %17
  store i32 0, ptr %19, align 4, !tbaa !5
  %20 = add nsw i32 %8, 1
  store i32 %20, ptr @nn, align 4, !tbaa !5
  %.pre = load i32, ptr %13, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %16, %7
  %22 = phi i32 [ %.pre, %16 ], [ %14, %7 ]
  %23 = phi i32 [ %20, %16 ], [ %8, %7 ]
  %24 = add nsw i32 %.01112, -1
  %.not = icmp eq i32 %.01112, 0
  br i1 %.not, label %2, label %7, !llvm.loop !9
}

attributes #0 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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