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

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

; 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 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) #1

; Function Attrs: nounwind uwtable
define dso_local void @Expander__expandFunction__(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.tag_____SetEntry__Ptr__Array__Tag________, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.tag_____FunctionDef__, ptr %9, i32 0, i32 18
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %46

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.tag_____FunctionDef__, ptr %15, i32 0, i32 18
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !15
  br label %18

18:                                               ; preds = %42, %14
  %19 = load i32, ptr %6, align 4, !tbaa !15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.tag_____CustomSet__Ptr__Array__Tag________, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.tag_____Array__SetEntry__Ptr__Array__Tag__________, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = icmp slt i32 %19, %23
  br i1 %24, label %25, label %45

25:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tag_____CustomSet__Ptr__Array__Tag________, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.tag_____Array__SetEntry__Ptr__Array__Tag__________, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  %30 = load i32, ptr %6, align 4, !tbaa !15
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %struct.tag_____SetEntry__Ptr__Array__Tag________, ptr %29, i64 %31
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %32, i64 16, i1 false), !tbaa.struct !20
  %33 = getelementptr inbounds %struct.tag_____SetEntry__Ptr__Array__Tag________, ptr %7, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !21
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %42

36:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %37 = getelementptr inbounds %struct.tag_____SetEntry__Ptr__Array__Tag________, ptr %7, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !23
  store ptr %38, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  call void @Expander__expandFunctionVariant__(ptr noundef %39, ptr noundef %40, ptr noundef %41)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %42

42:                                               ; preds = %36, %25
  %43 = load i32, ptr %6, align 4, !tbaa !15
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br label %18, !llvm.loop !24

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

46:                                               ; preds = %45, %13
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 176}
!10 = !{!"tag_____FunctionDef__", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !12, i64 104, !6, i64 112, !13, i64 120, !13, i64 136, !14, i64 152, !12, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !13, i64 208}
!11 = !{!"", !12, i64 0, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !6, i64 0, !12, i64 8}
!14 = !{!"tag_____Tag__", !6, i64 0, !6, i64 8}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !12, i64 8}
!17 = !{!"tag_____CustomSet__Ptr__Array__Tag________", !18, i64 0, !12, i64 16, !12, i64 20, !12, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!"tag_____Array__SetEntry__Ptr__Array__Tag__________", !6, i64 0, !12, i64 8}
!19 = !{!17, !6, i64 0}
!20 = !{i64 0, i64 4, !15, i64 8, i64 8, !5}
!21 = !{!22, !12, i64 0}
!22 = !{!"tag_____SetEntry__Ptr__Array__Tag________", !12, i64 0, !6, i64 8}
!23 = !{!22, !6, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"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_____SetEntry__Ptr__Array__Tag________ = type { i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @Expander__expandFunction__(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 176
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !14
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %13
  %9 = phi i32 [ %14, %13 ], [ %7, %.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %13 ], [ 0, %.preheader ]
  %10 = load ptr, ptr %4, align 8, !tbaa !17
  %11 = getelementptr inbounds %struct.tag_____SetEntry__Ptr__Array__Tag________, ptr %10, i64 %indvars.iv
  %.sroa.0.0.copyload = load i32, ptr %11, align 8, !tbaa !18
  %.not = icmp eq i32 %.sroa.0.0.copyload, 0
  br i1 %.not, label %13, label %12

12:                                               ; preds = %.lr.ph
  %.sroa.41.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 8
  %.sroa.41.0.copyload = load ptr, ptr %.sroa.41.0..sroa_idx, align 8, !tbaa !19
  tail call void @Expander__expandFunctionVariant__(ptr noundef %0, ptr noundef %1, ptr noundef %.sroa.41.0.copyload)
  %.pre = load i32, ptr %6, align 8, !tbaa !14
  br label %13

13:                                               ; preds = %12, %.lr.ph
  %14 = phi i32 [ %.pre, %12 ], [ %9, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = sext i32 %14 to i64
  %16 = icmp slt i64 %indvars.iv.next, %15
  br i1 %16, label %.lr.ph, label %.loopexit, !llvm.loop !20

.loopexit:                                        ; preds = %13, %.preheader, %2
  ret void
}

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

attributes #0 = { 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" }

!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, !7, i64 176}
!6 = !{!"tag_____FunctionDef__", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !11, i64 104, !7, i64 112, !12, i64 120, !12, i64 136, !13, i64 152, !11, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !12, i64 208}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !7, i64 8}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !7, i64 0, !11, i64 8}
!13 = !{!"tag_____Tag__", !7, i64 0, !7, i64 8}
!14 = !{!15, !11, i64 8}
!15 = !{!"tag_____CustomSet__Ptr__Array__Tag________", !16, i64 0, !11, i64 16, !11, i64 20, !11, i64 24, !7, i64 32, !7, i64 40}
!16 = !{!"tag_____Array__SetEntry__Ptr__Array__Tag__________", !7, i64 0, !11, i64 8}
!17 = !{!15, !7, i64 0}
!18 = !{!11, !11, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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