; LLVM IR from nickmqb/muon :: bootstrap/mu.ll_CGenerator (writeTag__)

; 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.string__ = type { ptr, i32 }
%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.tag_____Array__Tag____ = type { ptr, i32 }

@mu_____string401 = external dso_local global %struct.string__, align 8
@mu_____string74 = external dso_local global %struct.string__, align 8
@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
declare dso_local void @StringBuilder__write__(ptr noundef, ptr, i32) #3

; Function Attrs: nounwind uwtable
define dso_local void @CGenerator__writeTag__(ptr noundef %0, ptr %1, ptr %2) #3 {
  %4 = alloca %struct.tag_____Tag__, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.tag_____Tag__, align 8
  %12 = alloca i32, align 4
  %13 = getelementptr inbounds { ptr, ptr }, ptr %4, i32 0, i32 0
  store ptr %1, ptr %13, align 8
  %14 = getelementptr inbounds { ptr, ptr }, ptr %4, i32 0, i32 1
  store ptr %2, ptr %14, align 8
  store ptr %0, 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 !9
  br label %15

15:                                               ; preds = %37, %3
  br label %16

16:                                               ; preds = %15
  %17 = getelementptr inbounds %struct.tag_____Tag__, ptr %4, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.tag_____Namespace__, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = and i32 %20, 65536
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %16
  br label %44

24:                                               ; preds = %16
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %27 = getelementptr inbounds %struct.tag_____Tag__, ptr %4, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  store ptr %28, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tag_____Array__Tag____, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !17
  %33 = icmp ult i32 %29, %32
  br i1 %33, label %37, label %34

34:                                               ; preds = %24
  %35 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  call void %36(i32 noundef -3)
  br label %37

37:                                               ; preds = %34, %24
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.tag_____Array__Tag____, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !19
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds %struct.tag_____Tag__, ptr %40, i64 %42
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %43, i64 16, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %15

44:                                               ; preds = %23
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.tag_____Tag__, ptr %4, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  call void @CGenerator__writeNs__(ptr noundef %45, ptr noundef %47)
  %48 = getelementptr inbounds %struct.tag_____Tag__, ptr %4, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %78

51:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %52 = getelementptr inbounds %struct.tag_____Tag__, ptr %4, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  store ptr %53, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %60, %51
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.tag_____Array__Tag____, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 8, !tbaa !17
  %59 = icmp slt i32 %55, %58
  br i1 %59, label %60, label %74

60:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #4
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.tag_____Array__Tag____, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !19
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.tag_____Tag__, ptr %63, i64 %65
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %66, i64 16, i1 false), !tbaa.struct !20
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds { ptr, ptr }, ptr %11, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8
  %70 = getelementptr inbounds { ptr, ptr }, ptr %11, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8
  call void @CGenerator__writeNestedTag__(ptr noundef %67, ptr %69, ptr %71)
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #4
  br label %54, !llvm.loop !21

74:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = load ptr, ptr @mu_____string401, align 8
  %77 = load i32, ptr getelementptr inbounds ({ ptr, i32 }, ptr @mu_____string401, i32 0, i32 1), align 8
  call void @StringBuilder__write__(ptr noundef %75, ptr %76, i32 %77)
  br label %78

78:                                               ; preds = %74, %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %83, %78
  %80 = load i32, ptr %12, align 4, !tbaa !9
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = icmp slt i32 %80, %81
  br i1 %82, label %83, label %89

83:                                               ; preds = %79
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load ptr, ptr @mu_____string74, align 8
  %86 = load i32, ptr getelementptr inbounds ({ ptr, i32 }, ptr @mu_____string74, i32 0, i32 1), align 8
  call void @StringBuilder__write__(ptr noundef %84, ptr %85, i32 %86)
  %87 = load i32, ptr %12, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %12, align 4, !tbaa !9
  br label %79, !llvm.loop !23

89:                                               ; preds = %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @CGenerator__writeNestedTag__(ptr noundef, ptr, ptr) #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"tag_____Tag__", !6, i64 0, !6, i64 8}
!13 = !{!14, !10, i64 28}
!14 = !{!"tag_____Namespace__", !15, 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}
!15 = !{!"", !6, i64 0, !10, i64 8}
!16 = !{!12, !6, i64 8}
!17 = !{!18, !10, i64 8}
!18 = !{!"tag_____Array__Tag____", !6, i64 0, !10, i64 8}
!19 = !{!18, !6, i64 0}
!20 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; 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.string__ = type { ptr, i32 }
%struct.tag_____Tag__ = type { ptr, ptr }

@mu_____string401 = external dso_local local_unnamed_addr global %struct.string__, align 8
@mu_____string74 = external dso_local local_unnamed_addr global %struct.string__, align 8
@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 @StringBuilder__write__(ptr noundef, ptr, i32) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @CGenerator__writeTag__(ptr noundef %0, ptr %1, ptr readonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 28
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = and i32 %5, 65536
  %.not25 = icmp eq i32 %6, 0
  br i1 %.not25, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %7 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  br label %8

8:                                                ; preds = %.lr.ph, %14
  %.sroa.418.027 = phi ptr [ %2, %.lr.ph ], [ %.sroa.418.0.copyload, %14 ]
  %.02226 = phi i32 [ 0, %.lr.ph ], [ %9, %14 ]
  %9 = add nuw nsw i32 %.02226, 1
  %10 = getelementptr inbounds i8, ptr %.sroa.418.027, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %.not24 = icmp eq i32 %11, 0
  br i1 %.not24, label %12, label %14

12:                                               ; preds = %8
  %13 = load ptr, ptr %7, align 8, !tbaa !14
  tail call void %13(i32 noundef -3) #2
  br label %14

14:                                               ; preds = %12, %8
  %15 = load ptr, ptr %.sroa.418.027, align 8, !tbaa !15
  %.sroa.016.0.copyload = load ptr, ptr %15, align 8, !tbaa !14
  %.sroa.418.0..sroa_idx = getelementptr inbounds i8, ptr %15, i64 8
  %.sroa.418.0.copyload = load ptr, ptr %.sroa.418.0..sroa_idx, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %.sroa.016.0.copyload, i64 28
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = and i32 %17, 65536
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %._crit_edge, label %8

._crit_edge:                                      ; preds = %14, %3
  %.022.lcssa = phi i32 [ 0, %3 ], [ %9, %14 ]
  %.sroa.016.0.lcssa = phi ptr [ %1, %3 ], [ %.sroa.016.0.copyload, %14 ]
  %.sroa.418.0.lcssa = phi ptr [ %2, %3 ], [ %.sroa.418.0.copyload, %14 ]
  tail call void @CGenerator__writeNs__(ptr noundef %0, ptr noundef nonnull %.sroa.016.0.lcssa)
  %.not23 = icmp eq ptr %.sroa.418.0.lcssa, null
  br i1 %.not23, label %29, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %19 = getelementptr inbounds i8, ptr %.sroa.418.0.lcssa, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph31, label %._crit_edge32

.lr.ph31:                                         ; preds = %.preheader, %.lr.ph31
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph31 ], [ 0, %.preheader ]
  %22 = load ptr, ptr %.sroa.418.0.lcssa, align 8, !tbaa !15
  %23 = getelementptr inbounds %struct.tag_____Tag__, ptr %22, i64 %indvars.iv
  %.sroa.0.0.copyload = load ptr, ptr %23, align 8, !tbaa !14
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 8
  %.sroa.4.0.copyload = load ptr, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !14
  tail call void @CGenerator__writeNestedTag__(ptr noundef %0, ptr %.sroa.0.0.copyload, ptr %.sroa.4.0.copyload)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = load i32, ptr %19, align 8, !tbaa !12
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv.next, %25
  br i1 %26, label %.lr.ph31, label %._crit_edge32, !llvm.loop !16

._crit_edge32:                                    ; preds = %.lr.ph31, %.preheader
  %27 = load ptr, ptr @mu_____string401, align 8
  %28 = load i32, ptr getelementptr inbounds (i8, ptr @mu_____string401, i64 8), align 8
  tail call void @StringBuilder__write__(ptr noundef %0, ptr %27, i32 %28)
  br label %29

29:                                               ; preds = %._crit_edge32, %._crit_edge
  %.not37 = icmp eq i32 %.022.lcssa, 0
  br i1 %.not37, label %._crit_edge36, label %.lr.ph35

.lr.ph35:                                         ; preds = %29, %.lr.ph35
  %.033 = phi i32 [ %32, %.lr.ph35 ], [ 0, %29 ]
  %30 = load ptr, ptr @mu_____string74, align 8
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @mu_____string74, i64 8), align 8
  tail call void @StringBuilder__write__(ptr noundef %0, ptr %30, i32 %31)
  %32 = add nuw i32 %.033, 1
  %exitcond.not = icmp eq i32 %32, %.022.lcssa
  br i1 %exitcond.not, label %._crit_edge36, label %.lr.ph35, !llvm.loop !18

._crit_edge36:                                    ; preds = %.lr.ph35, %29
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @CGenerator__writeNestedTag__(ptr noundef, 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 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}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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