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

; 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_____Error__ = type { ptr, %struct.tag_____IntRange__, %struct.string__ }
%struct.tag_____IntRange__ = type { i32, i32 }
%struct.string__ = type { ptr, i32 }
%struct.tag_____Tag__ = type { ptr, ptr }
%struct.Node__ = type { i32, ptr }
%struct.tag_____CallExpression__ = type { %struct.Node__, ptr, ptr, ptr, ptr, ptr }
%struct.tag_____List__Node____ = type { ptr, i32, i32 }
%struct.tag_____Namespace__ = type { %struct.string__, ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.tag_____TypeCheckerContext__ = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, i32, i8 }

@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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @List__add__Error____(ptr noundef, ptr noundef byval(%struct.tag_____Error__) align 8) #4

; Function Attrs: nounwind uwtable
declare dso_local void @Error__at__(ptr dead_on_unwind noalias writable sret(%struct.tag_____Error__) align 8, ptr noundef, i64, ptr, i32) #4

; Function Attrs: nounwind uwtable
declare dso_local i64 @RangeFinder__find__(i32, ptr) #4

; Function Attrs: nounwind uwtable
define dso_local { ptr, ptr } @TypeChecker__getTypeArgWithTypeFlags__(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr %4, i32 %5) #4 {
  %7 = alloca %struct.tag_____Tag__, align 8
  %8 = alloca %struct.string__, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca %struct.Node__, align 8
  %16 = alloca %struct.tag_____Tag__, align 8
  %17 = alloca i32, align 4
  %18 = alloca %struct.tag_____Error__, align 8
  %19 = alloca %struct.tag_____IntRange__, align 4
  %20 = getelementptr inbounds { ptr, i32 }, ptr %8, i32 0, i32 0
  store ptr %4, ptr %20, align 8
  %21 = getelementptr inbounds { ptr, i32 }, ptr %8, i32 0, i32 1
  store i32 %5, ptr %21, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i32 %2, ptr %11, align 4, !tbaa !9
  store i32 %3, ptr %12, align 4, !tbaa !9
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.tag_____CallExpression__, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.tag_____List__Node____, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !14
  %28 = icmp sge i32 %22, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %6
  call void @llvm.memset.p0.i64(ptr align 8 %7, i8 0, i64 16, i1 false)
  br label %100

30:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.tag_____CallExpression__, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  store ptr %33, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %34 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %34, ptr %14, align 4, !tbaa !9
  %35 = load i32, ptr %14, align 4, !tbaa !9
  %36 = load ptr, ptr %13, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tag_____List__Node____, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !14
  %39 = icmp ult i32 %35, %38
  br i1 %39, label %43, label %40

40:                                               ; preds = %30
  %41 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  call void %42(i32 noundef -3)
  br label %43

43:                                               ; preds = %40, %30
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #5
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.tag_____List__Node____, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = load i32, ptr %14, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds %struct.Node__, ptr %46, i64 %48
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %15, ptr align 8 %49, i64 16, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.start.p0(i64 16, ptr %16) #5
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds { i32, ptr }, ptr %15, i32 0, i32 0
  %52 = load i32, ptr %51, align 8
  %53 = getelementptr inbounds { i32, ptr }, ptr %15, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8
  %55 = call { ptr, ptr } @TypeChecker__resolveType__(ptr noundef %50, i32 %52, ptr %54, i32 noundef 0)
  %56 = getelementptr inbounds { ptr, ptr }, ptr %16, i32 0, i32 0
  %57 = extractvalue { ptr, ptr } %55, 0
  store ptr %57, ptr %56, align 8
  %58 = getelementptr inbounds { ptr, ptr }, ptr %16, i32 0, i32 1
  %59 = extractvalue { ptr, ptr } %55, 1
  store ptr %59, ptr %58, align 8
  %60 = getelementptr inbounds %struct.tag_____Tag__, ptr %16, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !18
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %64

63:                                               ; preds = %43
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %16, i64 16, i1 false), !tbaa.struct !20
  store i32 1, ptr %17, align 4
  br label %99

64:                                               ; preds = %43
  %65 = getelementptr inbounds %struct.tag_____Tag__, ptr %16, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !18
  %67 = getelementptr inbounds %struct.tag_____Namespace__, ptr %66, i32 0, i32 3
  %68 = load i32, ptr %67, align 4, !tbaa !21
  %69 = load i32, ptr %12, align 4, !tbaa !9
  %70 = and i32 %68, %69
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %82

72:                                               ; preds = %64
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds { i32, ptr }, ptr %15, i32 0, i32 0
  %75 = load i32, ptr %74, align 8
  %76 = getelementptr inbounds { i32, ptr }, ptr %15, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8
  %78 = getelementptr inbounds { ptr, ptr }, ptr %16, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8
  %80 = getelementptr inbounds { ptr, ptr }, ptr %16, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8
  call void @TypeChecker__recordTag__(ptr noundef %73, i32 %75, ptr %77, ptr %79, ptr %81)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %16, i64 16, i1 false), !tbaa.struct !20
  store i32 1, ptr %17, align 4
  br label %99

82:                                               ; preds = %64
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.tag_____TypeCheckerContext__, ptr %83, i32 0, i32 2
  %85 = load ptr, ptr %84, align 8, !tbaa !24
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.tag_____TypeCheckerContext__, ptr %86, i32 0, i32 5
  %88 = load ptr, ptr %87, align 8, !tbaa !26
  %89 = getelementptr inbounds { i32, ptr }, ptr %15, i32 0, i32 0
  %90 = load i32, ptr %89, align 8
  %91 = getelementptr inbounds { i32, ptr }, ptr %15, i32 0, i32 1
  %92 = load ptr, ptr %91, align 8
  %93 = call i64 @RangeFinder__find__(i32 %90, ptr %92)
  store i64 %93, ptr %19, align 4
  %94 = load i64, ptr %19, align 4
  %95 = getelementptr inbounds { ptr, i32 }, ptr %8, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8
  %97 = getelementptr inbounds { ptr, i32 }, ptr %8, i32 0, i32 1
  %98 = load i32, ptr %97, align 8
  call void @Error__at__(ptr dead_on_unwind writable sret(%struct.tag_____Error__) align 8 %18, ptr noundef %88, i64 %94, ptr %96, i32 %98)
  call void @List__add__Error____(ptr noundef %85, ptr noundef byval(%struct.tag_____Error__) align 8 %18)
  call void @llvm.memset.p0.i64(ptr align 8 %7, i8 0, i64 16, i1 false)
  store i32 1, ptr %17, align 4
  br label %99

99:                                               ; preds = %82, %72, %63
  call void @llvm.lifetime.end.p0(i64 16, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %100

100:                                              ; preds = %99, %29
  %101 = load { ptr, ptr }, ptr %7, align 8
  ret { ptr, ptr } %101
}

; Function Attrs: nounwind uwtable
declare dso_local { ptr, ptr } @TypeChecker__resolveType__(ptr noundef, i32, ptr, i32 noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local void @TypeChecker__recordTag__(ptr noundef, i32, ptr, ptr, ptr) #4

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: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"tag_____CallExpression__", !13, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"", !10, i64 0, !6, i64 8}
!14 = !{!15, !10, i64 8}
!15 = !{!"tag_____List__Node____", !6, i64 0, !10, i64 8, !10, i64 12}
!16 = !{!15, !6, i64 0}
!17 = !{i64 0, i64 4, !9, i64 8, i64 8, !5}
!18 = !{!19, !6, i64 0}
!19 = !{!"tag_____Tag__", !6, i64 0, !6, i64 8}
!20 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}
!21 = !{!22, !10, i64 28}
!22 = !{!"tag_____Namespace__", !23, i64 0, !6, i64 16, !10, i64 24, !10, 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, !10, i64 104}
!23 = !{!"", !6, i64 0, !10, i64 8}
!24 = !{!25, !6, i64 16}
!25 = !{!"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, !10, i64 120, !10, i64 124, !6, i64 128, !10, i64 136, !7, i64 140}
!26 = !{!25, !6, i64 40}


; 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_____Error__ = type { ptr, %struct.tag_____IntRange__, %struct.string__ }
%struct.tag_____IntRange__ = type { i32, i32 }
%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
declare dso_local void @List__add__Error____(ptr noundef, ptr noundef byval(%struct.tag_____Error__) align 8) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @Error__at__(ptr dead_on_unwind noalias writable sret(%struct.tag_____Error__) align 8, ptr noundef, i64, ptr, i32) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @RangeFinder__find__(i32, ptr) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local { ptr, ptr } @TypeChecker__getTypeArgWithTypeFlags__(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, ptr %4, i32 %5) local_unnamed_addr #1 {
  %7 = alloca %struct.tag_____Error__, align 8
  %8 = getelementptr inbounds i8, ptr %1, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %.not = icmp sgt i32 %11, %2
  br i1 %.not, label %12, label %36

12:                                               ; preds = %6
  %13 = icmp ugt i32 %11, %2
  br i1 %13, label %17, label %14

14:                                               ; preds = %12
  %15 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  tail call void %16(i32 noundef -3) #2
  br label %17

17:                                               ; preds = %14, %12
  %18 = load ptr, ptr %9, align 8, !tbaa !15
  %19 = zext i32 %2 to i64
  %20 = getelementptr inbounds %struct.Node__, ptr %18, i64 %19
  %.sroa.07.0.copyload = load i32, ptr %20, align 8, !tbaa !16
  %.sroa.610.0..sroa_idx = getelementptr inbounds i8, ptr %20, i64 8
  %.sroa.610.0.copyload = load ptr, ptr %.sroa.610.0..sroa_idx, align 8, !tbaa !14
  %21 = tail call { ptr, ptr } @TypeChecker__resolveType__(ptr noundef %0, i32 %.sroa.07.0.copyload, ptr %.sroa.610.0.copyload, i32 noundef 0)
  %22 = extractvalue { ptr, ptr } %21, 0
  %23 = extractvalue { ptr, ptr } %21, 1
  %24 = icmp eq ptr %22, null
  br i1 %24, label %36, label %25

25:                                               ; preds = %17
  %26 = getelementptr inbounds i8, ptr %22, i64 28
  %27 = load i32, ptr %26, align 4, !tbaa !17
  %28 = and i32 %27, %3
  %.not30 = icmp eq i32 %28, 0
  br i1 %.not30, label %30, label %29

29:                                               ; preds = %25
  tail call void @TypeChecker__recordTag__(ptr noundef %0, i32 %.sroa.07.0.copyload, ptr %.sroa.610.0.copyload, ptr nonnull %22, ptr %23)
  br label %36

30:                                               ; preds = %25
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  %33 = getelementptr inbounds i8, ptr %0, i64 40
  %34 = load ptr, ptr %33, align 8, !tbaa !22
  %35 = tail call i64 @RangeFinder__find__(i32 %.sroa.07.0.copyload, ptr %.sroa.610.0.copyload)
  call void @Error__at__(ptr dead_on_unwind nonnull writable sret(%struct.tag_____Error__) align 8 %7, ptr noundef %34, i64 %35, ptr %4, i32 %5)
  call void @List__add__Error____(ptr noundef %32, ptr noundef nonnull byval(%struct.tag_____Error__) align 8 %7)
  br label %36

36:                                               ; preds = %29, %30, %17, %6
  %.sroa.5.1 = phi ptr [ null, %6 ], [ %23, %29 ], [ null, %30 ], [ %23, %17 ]
  %.sroa.025.1 = phi ptr [ null, %6 ], [ %22, %29 ], [ null, %30 ], [ null, %17 ]
  %.fca.0.insert = insertvalue { ptr, ptr } poison, ptr %.sroa.025.1, 0
  %.fca.1.insert = insertvalue { ptr, ptr } %.fca.0.insert, ptr %.sroa.5.1, 1
  ret { ptr, ptr } %.fca.1.insert
}

; Function Attrs: nounwind uwtable
declare dso_local { ptr, ptr } @TypeChecker__resolveType__(ptr noundef, i32, ptr, i32 noundef) local_unnamed_addr #1

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass