; LLVM IR from nickmqb/muon :: bootstrap/mu.ll_TypeCheckerFirstPass (checkUnit__)

; 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_____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 @TypeCheckerFirstPass__checkUnit__(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.Node__, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.tag_____TypeCheckerContext__, ptr %13, i32 0, i32 5
  store ptr %12, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.tag_____CodeUnit__, ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  store ptr %17, 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 !15
  br label %18

18:                                               ; preds = %64, %2
  %19 = load i32, ptr %6, align 4, !tbaa !15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.tag_____List__Node____, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !16
  %23 = icmp slt i32 %19, %22
  br i1 %23, label %24, label %67

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tag_____List__Node____, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = load i32, ptr %6, align 4, !tbaa !15
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.Node__, ptr %27, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %30, i64 16, i1 false), !tbaa.struct !19
  %31 = getelementptr inbounds %struct.Node__, ptr %7, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !20
  switch i32 %32, label %61 [
    i32 31, label %33
    i32 34, label %41
    i32 1, label %49
    i32 21, label %57
    i32 0, label %60
  ]

33:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %34 = getelementptr inbounds %struct.Node__, ptr %7, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !22
  store ptr %35, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.tag_____TypeCheckerContext__, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !23
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  call void @TypeCheckerFirstPass__checkNamespace__(ptr noundef %36, ptr noundef %39, ptr noundef %40)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %64

41:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %42 = getelementptr inbounds %struct.Node__, ptr %7, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !22
  store ptr %43, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.tag_____TypeCheckerContext__, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !23
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  call void @TypeCheckerFirstPass__checkFunction__(ptr noundef %44, ptr noundef %47, ptr noundef %48)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %64

49:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %50 = getelementptr inbounds %struct.Node__, ptr %7, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !22
  store ptr %51, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.tag_____TypeCheckerContext__, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %54, align 8, !tbaa !23
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  call void @TypeCheckerFirstPass__checkStaticField__(ptr noundef %52, ptr noundef %55, ptr noundef %56)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %64

57:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %58 = getelementptr inbounds %struct.Node__, ptr %7, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !22
  store ptr %59, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %64

60:                                               ; preds = %24
  br label %61

61:                                               ; preds = %60, %24
  %62 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  call void %63(i32 noundef -5)
  br label %64

64:                                               ; preds = %61, %57, %49, %41, %33
  %65 = load i32, ptr %6, align 4, !tbaa !15
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  br label %18, !llvm.loop !24

67:                                               ; preds = %18
  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 @TypeCheckerFirstPass__checkStaticField__(ptr noundef, ptr noundef, ptr noundef) #3

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

; Function Attrs: nounwind uwtable
declare dso_local void @TypeCheckerFirstPass__checkFunction__(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 40}
!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 = !{!13, !6, i64 40}
!13 = !{!"tag_____CodeUnit__", !14, i64 0, !11, i64 16, !14, i64 24, !6, i64 40}
!14 = !{!"", !6, i64 0, !11, i64 8}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !11, i64 8}
!17 = !{!"tag_____List__Node____", !6, i64 0, !11, i64 8, !11, i64 12}
!18 = !{!17, !6, i64 0}
!19 = !{i64 0, i64 4, !15, i64 8, i64 8, !5}
!20 = !{!21, !11, i64 0}
!21 = !{!"", !11, i64 0, !6, i64 8}
!22 = !{!21, !6, i64 8}
!23 = !{!10, !6, i64 24}
!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.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 @TypeCheckerFirstPass__checkUnit__(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 40
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !14
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  br label %11

11:                                               ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %12 = load ptr, ptr %5, align 8, !tbaa !16
  %13 = getelementptr inbounds %struct.Node__, ptr %12, i64 %indvars.iv
  %.sroa.0.0.copyload = load i32, ptr %13, align 8, !tbaa !17
  %.sroa.43.0..sroa_idx = getelementptr inbounds i8, ptr %13, i64 8
  %.sroa.43.0.copyload = load ptr, ptr %.sroa.43.0..sroa_idx, align 8, !tbaa !18
  switch i32 %.sroa.0.0.copyload, label %20 [
    i32 31, label %14
    i32 34, label %16
    i32 1, label %18
    i32 21, label %22
  ]

14:                                               ; preds = %11
  %15 = load ptr, ptr %9, align 8, !tbaa !19
  tail call void @TypeCheckerFirstPass__checkNamespace__(ptr noundef %0, ptr noundef %15, ptr noundef %.sroa.43.0.copyload)
  br label %22

16:                                               ; preds = %11
  %17 = load ptr, ptr %9, align 8, !tbaa !19
  tail call void @TypeCheckerFirstPass__checkFunction__(ptr noundef %0, ptr noundef %17, ptr noundef %.sroa.43.0.copyload)
  br label %22

18:                                               ; preds = %11
  %19 = load ptr, ptr %9, align 8, !tbaa !19
  tail call void @TypeCheckerFirstPass__checkStaticField__(ptr noundef %0, ptr noundef %19, ptr noundef %.sroa.43.0.copyload)
  br label %22

20:                                               ; preds = %11
  %21 = load ptr, ptr %10, align 8, !tbaa !18
  tail call void %21(i32 noundef -5) #2
  br label %22

22:                                               ; preds = %11, %20, %18, %16, %14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr %6, align 8, !tbaa !14
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next, %24
  br i1 %25, label %11, label %._crit_edge, !llvm.loop !20

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @TypeCheckerFirstPass__checkFunction__(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, !7, i64 40}
!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, !7, i64 40}
!12 = !{!"tag_____CodeUnit__", !13, i64 0, !10, i64 16, !13, i64 24, !7, i64 40}
!13 = !{!"", !7, i64 0, !10, i64 8}
!14 = !{!15, !10, i64 8}
!15 = !{!"tag_____List__Node____", !7, i64 0, !10, i64 8, !10, i64 12}
!16 = !{!15, !7, i64 0}
!17 = !{!10, !10, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!6, !7, i64 24}
!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