; LLVM IR from nickmqb/muon :: bootstrap/mu.ll_CGenerator (sfNamespace__)

; 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_____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 }

@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 @CGenerator__sfNamespace__(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
  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
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.tag_____Namespace__, ptr %11, i32 0, i32 4
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, 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 %14

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

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

32:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %33 = 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 %33, i64 16, i1 false), !tbaa.struct !22
  %34 = getelementptr inbounds %struct.Node__, ptr %8, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !23
  switch i32 %35, label %46 [
    i32 22, label %36
    i32 1, label %41
    i32 0, label %47
  ]

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %37 = getelementptr inbounds %struct.Node__, ptr %8, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !24
  store ptr %38, ptr %9, align 8, !tbaa !5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  call void @CGenerator__sfNamespace__(ptr noundef %39, ptr noundef %40)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %50

41:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %42 = getelementptr inbounds %struct.Node__, ptr %8, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !24
  store ptr %43, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  call void @CGenerator__sfStaticField__(ptr noundef %44, ptr noundef %45)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %50

46:                                               ; preds = %32
  br label %50

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

50:                                               ; preds = %47, %46, %41, %36
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %51

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

54:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @CGenerator__sfStaticField__(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"}


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

@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 @CGenerator__sfNamespace__(ptr noundef %0, ptr nocapture noundef readonly %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, %17
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %17 ]
  %10 = load ptr, ptr %4, align 8, !tbaa !15
  %11 = getelementptr inbounds %struct.tag_____MapEntry__string__Node____, ptr %10, i64 %indvars.iv
  %.sroa.04.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
  %.not = icmp eq i32 %.sroa.04.0.copyload, 0
  br i1 %.not, label %17, label %12

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

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

14:                                               ; preds = %12
  tail call void @CGenerator__sfStaticField__(ptr noundef %0, ptr noundef %.sroa.6.0.copyload)
  br label %17

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

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

._crit_edge:                                      ; preds = %17, %2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @CGenerator__sfStaticField__(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"}


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