; LLVM IR from nickmqb/muon :: bootstrap/mu.ll_Expander (expandNamespace2__)

; 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.tag_____MapEntry__string__Node____ = type { i32, %struct.string__, %struct.Node__ }
%struct.string__ = type { ptr, i32 }
%struct.Node__ = type { i32, ptr }
%struct.tag_____SetEntry__Ptr__Array__Tag________ = type { i32, ptr }
%struct.tag_____Namespace__ = type { %struct.string__, ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.tag_____Map__string__Node____ = type { %struct.tag_____Array__MapEntry__string__Node______, i32, i32, i32 }
%struct.tag_____Array__MapEntry__string__Node______ = type { ptr, i32 }
%struct.tag_____CustomSet__Ptr__Array__Tag________ = type { %struct.tag_____Array__SetEntry__Ptr__Array__Tag__________, i32, i32, i32, ptr, ptr }
%struct.tag_____Array__SetEntry__Ptr__Array__Tag__________ = type { ptr, i32 }

@top_____abandonFn__ = external dso_local thread_local global ptr, align 8

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

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

; 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: nounwind uwtable
define dso_local void @Expander__expandNamespace2__(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.tag_____MapEntry__string__Node____, align 8
  %8 = alloca %struct.Node__, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.tag_____SetEntry__Ptr__Array__Tag________, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.tag_____Namespace__, ptr %14, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %17

17:                                               ; preds = %49, %2
  %18 = load i32, ptr %6, align 4, !tbaa !13
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tag_____Map__string__Node____, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.tag_____Array__MapEntry__string__Node______, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !14
  %23 = icmp slt i32 %18, %22
  br i1 %23, label %24, label %52

24:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 40, ptr %7) #4
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tag_____Map__string__Node____, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds %struct.tag_____Array__MapEntry__string__Node______, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = load i32, ptr %6, align 4, !tbaa !13
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.tag_____MapEntry__string__Node____, ptr %28, i64 %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %31, i64 40, i1 false), !tbaa.struct !18
  %32 = getelementptr inbounds %struct.tag_____MapEntry__string__Node____, ptr %7, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %49

35:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %36 = getelementptr inbounds %struct.tag_____MapEntry__string__Node____, ptr %7, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %36, i64 16, i1 false), !tbaa.struct !22
  %37 = getelementptr inbounds %struct.Node__, ptr %8, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !23
  switch i32 %38, label %44 [
    i32 22, label %39
    i32 0, label %45
  ]

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %40 = getelementptr inbounds %struct.Node__, ptr %8, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !24
  store ptr %41, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  call void @Expander__expandNamespace2__(ptr noundef %42, ptr noundef %43)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %48

44:                                               ; preds = %35
  br label %48

45:                                               ; preds = %35
  %46 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  call void %47(i32 noundef -5)
  br label %48

48:                                               ; preds = %45, %44, %39
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %49

49:                                               ; preds = %48, %24
  %50 = load i32, ptr %6, align 4, !tbaa !13
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #4
  br label %17, !llvm.loop !25

52:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.tag_____Namespace__, ptr %53, i32 0, i32 9
  %55 = load ptr, ptr %54, align 8, !tbaa !27
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %89

57:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.tag_____Namespace__, ptr %58, i32 0, i32 10
  %60 = load ptr, ptr %59, align 8, !tbaa !28
  store ptr %60, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %61

61:                                               ; preds = %85, %57
  %62 = load i32, ptr %11, align 4, !tbaa !13
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.tag_____CustomSet__Ptr__Array__Tag________, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds %struct.tag_____Array__SetEntry__Ptr__Array__Tag__________, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 8, !tbaa !29
  %67 = icmp slt i32 %62, %66
  br i1 %67, label %68, label %88

68:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.tag_____CustomSet__Ptr__Array__Tag________, ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds %struct.tag_____Array__SetEntry__Ptr__Array__Tag__________, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !32
  %73 = load i32, ptr %11, align 4, !tbaa !13
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds %struct.tag_____SetEntry__Ptr__Array__Tag________, ptr %72, i64 %74
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %75, i64 16, i1 false), !tbaa.struct !22
  %76 = getelementptr inbounds %struct.tag_____SetEntry__Ptr__Array__Tag________, ptr %12, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !33
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %85

79:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %80 = getelementptr inbounds %struct.tag_____SetEntry__Ptr__Array__Tag________, ptr %12, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !35
  store ptr %81, ptr %13, align 8, !tbaa !5
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  call void @Expander__expandStructVariant__(ptr noundef %82, ptr noundef %83, ptr noundef %84)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %85

85:                                               ; preds = %79, %68
  %86 = load i32, ptr %11, align 4, !tbaa !13
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  br label %61, !llvm.loop !36

88:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %89

89:                                               ; preds = %88, %52
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @Expander__expandStructVariant__(ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 32}
!10 = !{!"tag_____Namespace__", !11, i64 0, !6, i64 16, !12, i64 24, !12, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !12, i64 104}
!11 = !{!"", !6, i64 0, !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !12, i64 8}
!15 = !{!"tag_____Map__string__Node____", !16, i64 0, !12, i64 16, !12, i64 20, !12, i64 24}
!16 = !{!"tag_____Array__MapEntry__string__Node______", !6, i64 0, !12, i64 8}
!17 = !{!15, !6, i64 0}
!18 = !{i64 0, i64 4, !13, i64 8, i64 8, !5, i64 16, i64 4, !13, i64 24, i64 4, !13, i64 32, i64 8, !5}
!19 = !{!20, !12, i64 0}
!20 = !{!"tag_____MapEntry__string__Node____", !12, i64 0, !11, i64 8, !21, i64 24}
!21 = !{!"", !12, i64 0, !6, i64 8}
!22 = !{i64 0, i64 4, !13, i64 8, i64 8, !5}
!23 = !{!21, !12, i64 0}
!24 = !{!21, !6, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!10, !6, i64 72}
!28 = !{!10, !6, i64 80}
!29 = !{!30, !12, i64 8}
!30 = !{!"tag_____CustomSet__Ptr__Array__Tag________", !31, i64 0, !12, i64 16, !12, i64 20, !12, i64 24, !6, i64 32, !6, i64 40}
!31 = !{!"tag_____Array__SetEntry__Ptr__Array__Tag__________", !6, i64 0, !12, i64 8}
!32 = !{!30, !6, i64 0}
!33 = !{!34, !12, i64 0}
!34 = !{!"tag_____SetEntry__Ptr__Array__Tag________", !12, i64 0, !6, i64 8}
!35 = !{!34, !6, i64 8}
!36 = distinct !{!36, !26}


; 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.tag_____MapEntry__string__Node____ = type { i32, %struct.string__, %struct.Node__ }
%struct.string__ = type { ptr, i32 }
%struct.Node__ = type { i32, ptr }
%struct.tag_____SetEntry__Ptr__Array__Tag________ = type { i32, ptr }

@top_____abandonFn__ = external dso_local thread_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: nounwind uwtable
define dso_local void @Expander__expandNamespace2__(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !12
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %8 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  br label %9

9:                                                ; preds = %.lr.ph, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %16 ]
  %10 = load ptr, ptr %4, align 8, !tbaa !15
  %11 = getelementptr inbounds %struct.tag_____MapEntry__string__Node____, ptr %10, i64 %indvars.iv
  %.sroa.010.0.copyload = load i32, ptr %11, align 8, !tbaa !16
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 32
  %.sroa.6.0.copyload = load ptr, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !17
  %.not26 = icmp eq i32 %.sroa.010.0.copyload, 0
  br i1 %.not26, label %16, label %12

12:                                               ; preds = %9
  %.sroa.412.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 24
  %.sroa.412.0.copyload = load i32, ptr %.sroa.412.0..sroa_idx, align 8, !tbaa !16
  switch i32 %.sroa.412.0.copyload, label %16 [
    i32 22, label %13
    i32 0, label %14
  ]

13:                                               ; preds = %12
  tail call void @Expander__expandNamespace2__(ptr noundef %0, ptr noundef %.sroa.6.0.copyload)
  br label %16

14:                                               ; preds = %12
  %15 = load ptr, ptr %8, align 8, !tbaa !17
  tail call void %15(i32 noundef -5) #2
  br label %16

16:                                               ; preds = %13, %14, %12, %9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr %5, align 8, !tbaa !12
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %9, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %16, %2
  %20 = getelementptr inbounds i8, ptr %1, i64 72
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %.loopexit, label %22

22:                                               ; preds = %._crit_edge
  %23 = getelementptr inbounds i8, ptr %1, i64 80
  %24 = load ptr, ptr %23, align 8, !tbaa !21
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load i32, ptr %25, align 8, !tbaa !22
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.lr.ph30, label %.loopexit

.lr.ph30:                                         ; preds = %22, %32
  %28 = phi i32 [ %33, %32 ], [ %26, %22 ]
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %32 ], [ 0, %22 ]
  %29 = load ptr, ptr %24, align 8, !tbaa !25
  %30 = getelementptr inbounds %struct.tag_____SetEntry__Ptr__Array__Tag________, ptr %29, i64 %indvars.iv32
  %.sroa.0.0.copyload = load i32, ptr %30, align 8, !tbaa !16
  %.not25 = icmp eq i32 %.sroa.0.0.copyload, 0
  br i1 %.not25, label %32, label %31

31:                                               ; preds = %.lr.ph30
  %.sroa.41.0..sroa_idx = getelementptr inbounds i8, ptr %30, i64 8
  %.sroa.41.0.copyload = load ptr, ptr %.sroa.41.0..sroa_idx, align 8, !tbaa !17
  tail call void @Expander__expandStructVariant__(ptr noundef %0, ptr noundef %1, ptr noundef %.sroa.41.0.copyload)
  %.pre = load i32, ptr %25, align 8, !tbaa !22
  br label %32

32:                                               ; preds = %31, %.lr.ph30
  %33 = phi i32 [ %.pre, %31 ], [ %28, %.lr.ph30 ]
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %34 = sext i32 %33 to i64
  %35 = icmp slt i64 %indvars.iv.next33, %34
  br i1 %35, label %.lr.ph30, label %.loopexit, !llvm.loop !26

.loopexit:                                        ; preds = %32, %22, %._crit_edge
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @Expander__expandStructVariant__(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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, !8, i64 32}
!6 = !{!"tag_____Namespace__", !7, i64 0, !8, i64 16, !11, i64 24, !11, i64 28, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !11, i64 104}
!7 = !{!"", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!13, !11, i64 8}
!13 = !{!"tag_____Map__string__Node____", !14, i64 0, !11, i64 16, !11, i64 20, !11, i64 24}
!14 = !{!"tag_____Array__MapEntry__string__Node______", !8, i64 0, !11, i64 8}
!15 = !{!13, !8, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!8, !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !8, i64 72}
!21 = !{!6, !8, i64 80}
!22 = !{!23, !11, i64 8}
!23 = !{!"tag_____CustomSet__Ptr__Array__Tag________", !24, i64 0, !11, i64 16, !11, i64 20, !11, i64 24, !8, i64 32, !8, i64 40}
!24 = !{!"tag_____Array__SetEntry__Ptr__Array__Tag__________", !8, i64 0, !11, i64 8}
!25 = !{!23, !8, i64 0}
!26 = distinct !{!26, !19}


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