; LLVM IR from nickmqb/muon :: bootstrap/mu.ll_TypeChecker (doStructPass__)

; 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.Node__ = type { i32, ptr }
%struct.tag_____TypeCheckerContext__ = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, i32, i8 }
%struct.tag_____List__Ptr__CodeUnit______ = type { ptr, i32, i32 }
%struct.tag_____CodeUnit__ = type { %struct.string__, i32, %struct.string__, ptr }
%struct.string__ = type { ptr, i32 }
%struct.tag_____List__Node____ = type { ptr, i32, 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 @TypeChecker__doStructPass__(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.Node__, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.tag_____TypeCheckerContext__, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %13

13:                                               ; preds = %60, %1
  %14 = load i32, ptr %4, align 4, !tbaa !12
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.tag_____List__Ptr__CodeUnit______, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %19, label %63

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.tag_____List__Ptr__CodeUnit______, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load i32, ptr %4, align 4, !tbaa !12
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %22, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.tag_____TypeCheckerContext__, ptr %28, i32 0, i32 5
  store ptr %27, ptr %29, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tag_____CodeUnit__, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  store ptr %32, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %33

33:                                               ; preds = %57, %19
  %34 = load i32, ptr %7, align 4, !tbaa !12
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tag_____List__Node____, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !20
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %39, label %60

39:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tag_____List__Node____, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !22
  %43 = load i32, ptr %7, align 4, !tbaa !12
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.Node__, ptr %42, i64 %44
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %45, i64 16, i1 false), !tbaa.struct !23
  %46 = getelementptr inbounds %struct.Node__, ptr %8, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !24
  switch i32 %47, label %53 [
    i32 31, label %48
    i32 0, label %54
  ]

48:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %49 = getelementptr inbounds %struct.Node__, ptr %8, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !26
  store ptr %50, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  call void @TypeChecker__checkNamespaceDefStructs__(ptr noundef %51, ptr noundef %52)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %57

53:                                               ; preds = %39
  br label %57

54:                                               ; preds = %39
  %55 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  call void %56(i32 noundef -5)
  br label %57

57:                                               ; preds = %54, %53, %48
  %58 = load i32, ptr %7, align 4, !tbaa !12
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %33, !llvm.loop !27

60:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %61 = load i32, ptr %4, align 4, !tbaa !12
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %13, !llvm.loop !29

63:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @TypeChecker__checkNamespaceDefStructs__(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 8}
!10 = !{!"tag_____TypeCheckerContext__", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !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, !6, i64 104, !6, i64 112, !11, i64 120, !11, i64 124, !6, i64 128, !11, i64 136, !7, i64 140}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 8}
!14 = !{!"tag_____List__Ptr__CodeUnit______", !6, i64 0, !11, i64 8, !11, i64 12}
!15 = !{!14, !6, i64 0}
!16 = !{!10, !6, i64 40}
!17 = !{!18, !6, i64 40}
!18 = !{!"tag_____CodeUnit__", !19, i64 0, !11, i64 16, !19, i64 24, !6, i64 40}
!19 = !{!"", !6, i64 0, !11, i64 8}
!20 = !{!21, !11, i64 8}
!21 = !{!"tag_____List__Node____", !6, i64 0, !11, i64 8, !11, i64 12}
!22 = !{!21, !6, i64 0}
!23 = !{i64 0, i64 4, !12, i64 8, i64 8, !5}
!24 = !{!25, !11, i64 0}
!25 = !{!"", !11, i64 0, !6, i64 8}
!26 = !{!25, !6, i64 8}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = distinct !{!29, !28}


; 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.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 @TypeChecker__doStructPass__(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !11
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph20, label %._crit_edge21

.lr.ph20:                                         ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  br label %9

9:                                                ; preds = %.lr.ph20, %._crit_edge
  %10 = phi i32 [ %5, %.lr.ph20 ], [ %28, %._crit_edge ]
  %indvars.iv23 = phi i64 [ 0, %.lr.ph20 ], [ %indvars.iv.next24, %._crit_edge ]
  %11 = load ptr, ptr %3, align 8, !tbaa !13
  %12 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv23
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  store ptr %13, ptr %7, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %13, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !19
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9, %24
  %indvars.iv = phi i64 [ %indvars.iv.next, %24 ], [ 0, %9 ]
  %19 = load ptr, ptr %15, align 8, !tbaa !21
  %20 = getelementptr inbounds %struct.Node__, ptr %19, i64 %indvars.iv
  %.sroa.0.0.copyload = load i32, ptr %20, align 8, !tbaa !22
  switch i32 %.sroa.0.0.copyload, label %24 [
    i32 31, label %21
    i32 0, label %22
  ]

21:                                               ; preds = %.lr.ph
  %.sroa.41.0..sroa_idx = getelementptr inbounds i8, ptr %20, i64 8
  %.sroa.41.0.copyload = load ptr, ptr %.sroa.41.0..sroa_idx, align 8, !tbaa !14
  tail call void @TypeChecker__checkNamespaceDefStructs__(ptr noundef %0, ptr noundef %.sroa.41.0.copyload)
  br label %24

22:                                               ; preds = %.lr.ph
  %23 = load ptr, ptr %8, align 8, !tbaa !14
  tail call void %23(i32 noundef -5) #2
  br label %24

24:                                               ; preds = %.lr.ph, %22, %21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr %16, align 8, !tbaa !19
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next, %26
  br i1 %27, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !23

._crit_edge.loopexit:                             ; preds = %24
  %.pre = load i32, ptr %4, align 8, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %9
  %28 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %10, %9 ]
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %29 = sext i32 %28 to i64
  %30 = icmp slt i64 %indvars.iv.next24, %29
  br i1 %30, label %9, label %._crit_edge21, !llvm.loop !25

._crit_edge21:                                    ; preds = %._crit_edge, %1
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @TypeChecker__checkNamespaceDefStructs__(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, !7, i64 8}
!6 = !{!"tag_____TypeCheckerContext__", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !10, i64 120, !10, i64 124, !7, i64 128, !10, i64 136, !8, i64 140}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"tag_____List__Ptr__CodeUnit______", !7, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!12, !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !7, i64 40}
!16 = !{!17, !7, i64 40}
!17 = !{!"tag_____CodeUnit__", !18, i64 0, !10, i64 16, !18, i64 24, !7, i64 40}
!18 = !{!"", !7, i64 0, !10, i64 8}
!19 = !{!20, !10, i64 8}
!20 = !{!"tag_____List__Node____", !7, i64 0, !10, i64 8, !10, i64 12}
!21 = !{!20, !7, i64 0}
!22 = !{!10, !10, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


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