; LLVM IR from Dev-XYS/Algorithms :: Persistent-Trie.ll (Z4initv)

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

@V = external dso_local global [100010 x %struct.vertex], align 16
@n = external dso_local global i32, align 4
@fa = external dso_local global [100010 x [18 x i32]], align 16
@k = external dso_local global i32, align 4

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(212)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsiii(i32 noundef, i32 noundef, i32 noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4initv() #4 personality ptr @__gxx_personality_v0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 216) #5
  invoke void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(212) %4)
          to label %5 unwind label %17

5:                                                ; preds = %0
  store ptr %4, ptr getelementptr inbounds (%struct.vertex, ptr getelementptr inbounds ([100010 x %struct.vertex], ptr @V, i64 0, i64 1), i32 0, i32 2), align 8, !tbaa !5
  call void @_Z3dfsiii(i32 noundef 1, i32 noundef 0, i32 noundef 0)
  store i32 1, ptr @k, align 4, !tbaa !11
  br label %6

6:                                                ; preds = %47, %5
  %7 = load i32, ptr @k, align 4, !tbaa !11
  %8 = shl i32 1, %7
  %9 = load i32, ptr @n, align 4, !tbaa !11
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %11, label %50

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 1, ptr %3, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %43, %11
  %13 = load i32, ptr %3, align 4, !tbaa !11
  %14 = load i32, ptr @n, align 4, !tbaa !11
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %21, label %16

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

17:                                               ; preds = %0
  %18 = landingpad { ptr, i32 }
          cleanup
  %19 = extractvalue { ptr, i32 } %18, 0
  store ptr %19, ptr %1, align 8
  %20 = extractvalue { ptr, i32 } %18, 1
  store i32 %20, ptr %2, align 4
  call void @_ZdlPvm(ptr noundef %4, i64 noundef 216) #7
  br label %53

21:                                               ; preds = %12
  %22 = load i32, ptr %3, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %23
  %25 = load i32, ptr @k, align 4, !tbaa !11
  %26 = sub nsw i32 %25, 1
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [18 x i32], ptr %24, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %30
  %32 = load i32, ptr @k, align 4, !tbaa !11
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [18 x i32], ptr %31, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = load i32, ptr %3, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %38
  %40 = load i32, ptr @k, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [18 x i32], ptr %39, i64 0, i64 %41
  store i32 %36, ptr %42, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %21
  %44 = load i32, ptr %3, align 4, !tbaa !11
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %3, align 4, !tbaa !11
  br label %12, !llvm.loop !12

46:                                               ; preds = %16
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr @k, align 4, !tbaa !11
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @k, align 4, !tbaa !11
  br label %6, !llvm.loop !14

50:                                               ; preds = %6
  %51 = load i32, ptr @k, align 4, !tbaa !11
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr @k, align 4, !tbaa !11
  ret void

53:                                               ; preds = %17
  %54 = load ptr, ptr %1, align 8
  %55 = load i32, ptr %2, align 4
  %56 = insertvalue { ptr, i32 } poison, ptr %54, 0
  %57 = insertvalue { ptr, i32 } %56, i32 %55, 1
  resume { ptr, i32 } %57
}

attributes #0 = { nobuiltin allocsize(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 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 = { nobuiltin nounwind "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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { nounwind }
attributes #7 = { builtin 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, !10, i64 8}
!6 = !{!"_ZTS6vertex", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@V = external dso_local local_unnamed_addr global [100010 x %struct.vertex], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@fa = external dso_local local_unnamed_addr global [100010 x [18 x i32]], align 16
@k = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(212)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4initv() local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %1 = tail call noalias noundef nonnull dereferenceable(216) ptr @_Znwm(i64 noundef 216) #3
  tail call void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(212) %1)
  store ptr %1, ptr getelementptr inbounds (i8, ptr @V, i64 24), align 8, !tbaa !5
  tail call void @_Z3dfsiii(i32 noundef 1, i32 noundef 0, i32 noundef 0)
  %2 = load i32, ptr @n, align 4, !tbaa !11
  %.not8 = icmp slt i32 %2, 2
  br i1 %.not8, label %._crit_edge10, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %3 = zext nneg i32 %2 to i64
  %xtraiter = and i64 %3, 1
  %unroll_iter = and i64 %3, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv14 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next15, %._crit_edge ]
  %4 = add nsw i64 %indvars.iv14, -1
  br label %13

._crit_edge.unr-lcssa:                            ; preds = %13
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %5 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %indvars.iv.next.1, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %7, i64 %4
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %indvars.iv.next.1, i64 %indvars.iv14
  store i32 %9, ptr %10, align 4, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %indvars.iv.next15 = add nuw nsw i64 %indvars.iv14, 1
  %11 = trunc nuw nsw i64 %indvars.iv14 to i32
  %12 = shl nuw i32 2, %11
  %.not = icmp sgt i32 %12, %2
  br i1 %.not, label %._crit_edge10, label %.preheader, !llvm.loop !12

13:                                               ; preds = %13, %.preheader
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next.1, %13 ]
  %niter = phi i64 [ 0, %.preheader ], [ %niter.next.1, %13 ]
  %14 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %indvars.iv, i64 %4
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %16, i64 %4
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %indvars.iv, i64 %indvars.iv14
  store i32 %18, ptr %19, align 4, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %indvars.iv.next, i64 %4
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %22, i64 %4
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = getelementptr inbounds [100010 x [18 x i32]], ptr @fa, i64 0, i64 %indvars.iv.next, i64 %indvars.iv14
  store i32 %24, ptr %25, align 4, !tbaa !11
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %13, !llvm.loop !14

._crit_edge10:                                    ; preds = %._crit_edge, %0
  %storemerge.lcssa7 = phi i32 [ 0, %0 ], [ %11, %._crit_edge ]
  store i32 %storemerge.lcssa7, ptr @k, align 4, !tbaa !11
  ret void
}

attributes #0 = { nobuiltin allocsize(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 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 = { 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 #3 = { builtin allocsize(0) }

!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, !10, i64 8}
!6 = !{!"_ZTS6vertex", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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