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

; 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__Tag____ = type { i32, %struct.tag_____Tag__ }
%struct.tag_____Tag__ = type { ptr, ptr }
%struct.tag_____Namespace__ = type { %struct.string__, ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.string__ = type { ptr, i32 }
%struct.tag_____Set__Tag____ = type { %struct.tag_____Array__SetEntry__Tag______, i32, i32, i32 }
%struct.tag_____Array__SetEntry__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
declare dso_local ptr @TypeChecker__closeTagArgs__(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @Expander__expandStructVariant__(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.tag_____SetEntry__Tag____, align 8
  %10 = alloca %struct.tag_____Tag__, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.tag_____Namespace__, ptr %12, i32 0, i32 12
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %64

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tag_____Namespace__, ptr %17, i32 0, i32 12
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  store ptr %19, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %20

20:                                               ; preds = %60, %16
  %21 = load i32, ptr %8, align 4, !tbaa !13
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.tag_____Set__Tag____, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.tag_____Array__SetEntry__Tag______, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = icmp slt i32 %21, %25
  br i1 %26, label %27, label %63

27:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #3
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.tag_____Set__Tag____, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct.tag_____Array__SetEntry__Tag______, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = load i32, ptr %8, align 4, !tbaa !13
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.tag_____SetEntry__Tag____, ptr %31, i64 %33
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %34, i64 24, i1 false), !tbaa.struct !18
  %35 = getelementptr inbounds %struct.tag_____SetEntry__Tag____, ptr %9, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !19
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %60

38:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #3
  %39 = getelementptr inbounds %struct.tag_____SetEntry__Tag____, ptr %9, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %39, i64 16, i1 false), !tbaa.struct !22
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %40 = getelementptr inbounds %struct.tag_____Tag__, ptr %10, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !23
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.tag_____Namespace__, ptr %42, i32 0, i32 9
  %44 = load ptr, ptr %43, align 8, !tbaa !24
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = call ptr @TypeChecker__closeTagArgs__(ptr noundef %41, ptr noundef %44, ptr noundef %45)
  store ptr %46, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tag_____Tag__, ptr %10, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !25
  %49 = getelementptr inbounds %struct.tag_____Namespace__, ptr %48, i32 0, i32 10
  %50 = load ptr, ptr %49, align 8, !tbaa !26
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = call zeroext i8 @CustomSet__tryAdd__Ptr__Array__Tag________(ptr noundef %50, ptr noundef %51)
  %53 = icmp ne i8 %52, 0
  br i1 %53, label %54, label %59

54:                                               ; preds = %38
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.tag_____Tag__, ptr %10, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !25
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  call void @Expander__expandStructVariant__(ptr noundef %55, ptr noundef %57, ptr noundef %58)
  br label %59

59:                                               ; preds = %54, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #3
  br label %60

60:                                               ; preds = %59, %27
  %61 = load i32, ptr %8, align 4, !tbaa !13
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %8, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #3
  br label %20, !llvm.loop !27

63:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %64

64:                                               ; preds = %63, %3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @CustomSet__tryAdd__Ptr__Array__Tag________(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 96}
!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_____Set__Tag____", !16, i64 0, !12, i64 16, !12, i64 20, !12, i64 24}
!16 = !{!"tag_____Array__SetEntry__Tag______", !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 8, !5}
!19 = !{!20, !12, i64 0}
!20 = !{!"tag_____SetEntry__Tag____", !12, i64 0, !21, i64 8}
!21 = !{!"tag_____Tag__", !6, i64 0, !6, i64 8}
!22 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}
!23 = !{!21, !6, i64 8}
!24 = !{!10, !6, i64 72}
!25 = !{!21, !6, i64 0}
!26 = !{!10, !6, i64 80}
!27 = distinct !{!27, !28}
!28 = !{!"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__Tag____ = type { i32, %struct.tag_____Tag__ }
%struct.tag_____Tag__ = type { ptr, ptr }

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

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

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

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %1, i64 72
  br label %10

10:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %11 = load ptr, ptr %5, align 8, !tbaa !15
  %12 = getelementptr inbounds %struct.tag_____SetEntry__Tag____, ptr %11, i64 %indvars.iv
  %.sroa.03.0.copyload = load i32, ptr %12, align 8, !tbaa !16
  %.sroa.44.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 8
  %.sroa.44.0.copyload = load ptr, ptr %.sroa.44.0..sroa_idx, align 8, !tbaa !17
  %.not16 = icmp eq i32 %.sroa.03.0.copyload, 0
  br i1 %.not16, label %20, label %13

13:                                               ; preds = %10
  %.sroa.55.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 16
  %.sroa.55.0.copyload = load ptr, ptr %.sroa.55.0..sroa_idx, align 8, !tbaa !17
  %14 = load ptr, ptr %9, align 8, !tbaa !18
  %15 = tail call ptr @TypeChecker__closeTagArgs__(ptr noundef %.sroa.55.0.copyload, ptr noundef %14, ptr noundef %2)
  %16 = getelementptr inbounds i8, ptr %.sroa.44.0.copyload, i64 80
  %17 = load ptr, ptr %16, align 8, !tbaa !19
  %18 = tail call zeroext i8 @CustomSet__tryAdd__Ptr__Array__Tag________(ptr noundef %17, ptr noundef %15)
  %.not17 = icmp eq i8 %18, 0
  br i1 %.not17, label %20, label %19

19:                                               ; preds = %13
  tail call void @Expander__expandStructVariant__(ptr noundef %0, ptr noundef nonnull %.sroa.44.0.copyload, ptr noundef %15)
  br label %20

20:                                               ; preds = %13, %19, %10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i32, ptr %6, align 8, !tbaa !12
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %10, label %.loopexit, !llvm.loop !20

.loopexit:                                        ; preds = %20, %.preheader, %3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @CustomSet__tryAdd__Ptr__Array__Tag________(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, !8, i64 96}
!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_____Set__Tag____", !14, i64 0, !11, i64 16, !11, i64 20, !11, i64 24}
!14 = !{!"tag_____Array__SetEntry__Tag______", !8, i64 0, !11, i64 8}
!15 = !{!13, !8, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!8, !8, i64 0}
!18 = !{!6, !8, i64 72}
!19 = !{!6, !8, i64 80}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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