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

; 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_____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_____Array__Tag____ = type { ptr, 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: 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
define dso_local { ptr, ptr } @TypeChecker__closeTag__(ptr %0, ptr %1, ptr noundef %2, ptr noundef %3) #4 {
  %5 = alloca %struct.tag_____Tag__, align 8
  %6 = alloca %struct.tag_____Tag__, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = getelementptr inbounds { ptr, ptr }, ptr %6, i32 0, i32 0
  store ptr %0, ptr %14, align 8
  %15 = getelementptr inbounds { ptr, ptr }, ptr %6, i32 0, i32 1
  store ptr %1, ptr %15, align 8
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #5
  %16 = getelementptr inbounds %struct.tag_____Tag__, ptr %6, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  %19 = zext i1 %18 to i32
  %20 = trunc i32 %19 to i8
  store i8 %20, ptr %9, align 1, !tbaa !11
  %21 = load i8, ptr %9, align 1, !tbaa !11
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %23, label %32

23:                                               ; preds = %4
  %24 = getelementptr inbounds %struct.tag_____Tag__, ptr %6, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.tag_____Namespace__, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !12
  %28 = and i32 %27, 16384
  %29 = icmp ne i32 %28, 0
  %30 = zext i1 %29 to i32
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %9, align 1, !tbaa !11
  br label %32

32:                                               ; preds = %23, %4
  %33 = load i8, ptr %9, align 1, !tbaa !11
  %34 = icmp ne i8 %33, 0
  br i1 %34, label %35, label %57

35:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tag_____Tag__, ptr %6, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = call i32 @TypeChecker__findTypeParamIndex__(ptr noundef %36, ptr noundef %38)
  store i32 %39, ptr %10, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %40, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %41 = load i32, ptr %10, align 4, !tbaa !16
  store i32 %41, ptr %12, align 4, !tbaa !16
  %42 = load i32, ptr %12, align 4, !tbaa !16
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.tag_____Array__Tag____, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !17
  %46 = icmp ult i32 %42, %45
  br i1 %46, label %50, label %47

47:                                               ; preds = %35
  %48 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  call void %49(i32 noundef -3)
  br label %50

50:                                               ; preds = %47, %35
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.tag_____Array__Tag____, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  %54 = load i32, ptr %12, align 4, !tbaa !16
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds %struct.tag_____Tag__, ptr %53, i64 %55
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %56, i64 16, i1 false), !tbaa.struct !20
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %72

57:                                               ; preds = %32
  %58 = getelementptr inbounds %struct.tag_____Tag__, ptr %6, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  %60 = icmp eq ptr %59, null
  br i1 %60, label %61, label %62

61:                                               ; preds = %57
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !20
  store i32 1, ptr %13, align 4
  br label %72

62:                                               ; preds = %57
  call void @llvm.memset.p0.i64(ptr align 8 %5, i8 0, i64 16, i1 false)
  %63 = getelementptr inbounds %struct.tag_____Tag__, ptr %6, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.tag_____Tag__, ptr %5, i32 0, i32 0
  store ptr %64, ptr %65, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.tag_____Tag__, ptr %6, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = call ptr @TypeChecker__closeTagArgs__(ptr noundef %67, ptr noundef %68, ptr noundef %69)
  %71 = getelementptr inbounds %struct.tag_____Tag__, ptr %5, i32 0, i32 1
  store ptr %70, ptr %71, align 8, !tbaa !21
  store i32 1, ptr %13, align 4
  br label %72

72:                                               ; preds = %62, %61, %50
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #5
  %73 = load { ptr, ptr }, ptr %5, align 8
  ret { ptr, ptr } %73
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TypeChecker__findTypeParamIndex__(ptr noundef, ptr noundef) #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, !6, i64 0}
!10 = !{!"tag_____Tag__", !6, i64 0, !6, i64 8}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !15, i64 28}
!13 = !{!"tag_____Namespace__", !14, i64 0, !6, i64 16, !15, i64 24, !15, 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, !15, i64 104}
!14 = !{!"", !6, i64 0, !15, i64 8}
!15 = !{!"int", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!18, !15, i64 8}
!18 = !{!"tag_____Array__Tag____", !6, i64 0, !15, i64 8}
!19 = !{!18, !6, i64 0}
!20 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}
!21 = !{!10, !6, i64 8}


; 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_____Tag__ = type { ptr, 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 { ptr, ptr } @TypeChecker__closeTag__(ptr %0, ptr %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.critedge, label %5

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 28
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = and i32 %7, 16384
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.critedge, label %10

10:                                               ; preds = %5
  %11 = tail call i32 @TypeChecker__findTypeParamIndex__(ptr noundef %2, ptr noundef nonnull %0)
  %12 = getelementptr inbounds i8, ptr %3, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !12
  %14 = icmp ult i32 %11, %13
  br i1 %14, label %18, label %15

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

18:                                               ; preds = %15, %10
  %19 = load ptr, ptr %3, align 8, !tbaa !15
  %20 = zext i32 %11 to i64
  %21 = getelementptr inbounds %struct.tag_____Tag__, ptr %19, i64 %20
  %.sroa.014.0.copyload = load ptr, ptr %21, align 8, !tbaa !14
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %21, i64 8
  %.sroa.5.0.copyload = load ptr, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !14
  br label %25

.critedge:                                        ; preds = %4, %5
  %22 = icmp eq ptr %1, null
  br i1 %22, label %25, label %23

23:                                               ; preds = %.critedge
  %24 = tail call ptr @TypeChecker__closeTagArgs__(ptr noundef nonnull %1, ptr noundef %2, ptr noundef %3)
  br label %25

25:                                               ; preds = %.critedge, %23, %18
  %.sroa.5.0 = phi ptr [ %.sroa.5.0.copyload, %18 ], [ %24, %23 ], [ null, %.critedge ]
  %.sroa.014.0 = phi ptr [ %.sroa.014.0.copyload, %18 ], [ %0, %23 ], [ %0, %.critedge ]
  %.fca.0.insert = insertvalue { ptr, ptr } poison, ptr %.sroa.014.0, 0
  %.fca.1.insert = insertvalue { ptr, ptr } %.fca.0.insert, ptr %.sroa.5.0, 1
  ret { ptr, ptr } %.fca.1.insert
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TypeChecker__findTypeParamIndex__(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, !11, i64 28}
!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_____Array__Tag____", !8, i64 0, !11, i64 8}
!14 = !{!8, !8, i64 0}
!15 = !{!13, !8, i64 0}


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