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

; 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.Node__ = type { i32, ptr }
%struct.tag_____GenerateContext__ = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, ptr, ptr, %struct.string__, i32, %struct.string__, i32, ptr, ptr, i8 }
%struct.tag_____BlockStatement__ = type { ptr, ptr, ptr }
%struct.tag_____List__Node____ = type { ptr, i32, i32 }

@mu_____string308 = external dso_local global %struct.string__, align 8
@mu_____string314 = external dso_local global %struct.string__, 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 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) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @CodeBuilder__indent__(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @CodeBuilder__unIndent__(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @CGenerator__genBlockStatement__(ptr noundef %0, ptr noundef %1) #2 {
  %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.tag_____GenerateContext__, ptr %8, i32 0, i32 5
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr @mu_____string314, align 8
  %12 = load i32, ptr getelementptr inbounds ({ ptr, i32 }, ptr @mu_____string314, i32 0, i32 1), align 8
  call void @CodeBuilder__writeLine__(ptr noundef %10, ptr %11, i32 %12)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.tag_____GenerateContext__, ptr %13, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  call void @CodeBuilder__indent__(ptr noundef %15)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.tag_____BlockStatement__, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  store ptr %18, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !15
  br label %19

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

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tag_____List__Node____, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = load i32, ptr %6, align 4, !tbaa !15
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.Node__, ptr %28, i64 %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %31, i64 16, i1 false), !tbaa.struct !19
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds { i32, ptr }, ptr %7, i32 0, i32 0
  %34 = load i32, ptr %33, align 8
  %35 = getelementptr inbounds { i32, ptr }, ptr %7, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8
  call void @CGenerator__genStatement__(ptr noundef %32, i32 %34, ptr %36)
  %37 = load i32, ptr %6, align 4, !tbaa !15
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  br label %19, !llvm.loop !20

39:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tag_____GenerateContext__, ptr %40, i32 0, i32 5
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  call void @CodeBuilder__unIndent__(ptr noundef %42)
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.tag_____GenerateContext__, ptr %43, i32 0, i32 5
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = load ptr, ptr @mu_____string308, align 8
  %47 = load i32, ptr getelementptr inbounds ({ ptr, i32 }, ptr @mu_____string308, i32 0, i32 1), align 8
  call void @CodeBuilder__writeLine__(ptr noundef %45, ptr %46, i32 %47)
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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_____GenerateContext__", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !12, i64 80, !11, i64 96, !12, i64 104, !11, i64 120, !6, i64 128, !6, i64 136, !7, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !6, i64 0, !11, i64 8}
!13 = !{!14, !6, i64 8}
!14 = !{!"tag_____BlockStatement__", !6, i64 0, !6, i64 8, !6, i64 16}
!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 = distinct !{!20, !21}
!21 = !{!"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.string__ = type { ptr, i32 }
%struct.Node__ = type { i32, ptr }

@mu_____string308 = external dso_local local_unnamed_addr global %struct.string__, align 8
@mu_____string314 = external dso_local local_unnamed_addr global %struct.string__, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @CodeBuilder__writeLine__(ptr noundef, ptr, i32) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @CodeBuilder__indent__(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @CodeBuilder__unIndent__(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @CGenerator__genStatement__(ptr noundef, i32, ptr) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @CGenerator__genBlockStatement__(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr @mu_____string314, align 8
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @mu_____string314, i64 8), align 8
  tail call void @CodeBuilder__writeLine__(ptr noundef %4, ptr %5, i32 %6)
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @CodeBuilder__indent__(ptr noundef %7)
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %13 = load ptr, ptr %9, align 8, !tbaa !16
  %14 = getelementptr inbounds %struct.Node__, ptr %13, i64 %indvars.iv
  %.sroa.0.0.copyload = load i32, ptr %14, align 8, !tbaa !17
  %.sroa.41.0..sroa_idx = getelementptr inbounds i8, ptr %14, i64 8
  %.sroa.41.0.copyload = load ptr, ptr %.sroa.41.0..sroa_idx, align 8, !tbaa !18
  tail call void @CGenerator__genStatement__(ptr noundef %0, i32 %.sroa.0.0.copyload, ptr %.sroa.41.0.copyload)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = load i32, ptr %10, align 8, !tbaa !14
  %16 = sext i32 %15 to i64
  %17 = icmp slt i64 %indvars.iv.next, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph, %2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @CodeBuilder__unIndent__(ptr noundef %18)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr @mu_____string308, align 8
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @mu_____string308, i64 8), align 8
  tail call void @CodeBuilder__writeLine__(ptr noundef %19, ptr %20, i32 %21)
  ret void
}

attributes #0 = { 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" }

!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_____GenerateContext__", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !7, i64 56, !7, i64 64, !7, i64 72, !11, i64 80, !10, i64 96, !11, i64 104, !10, i64 120, !7, i64 128, !7, i64 136, !8, i64 144}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !7, i64 0, !10, i64 8}
!12 = !{!13, !7, i64 8}
!13 = !{!"tag_____BlockStatement__", !7, i64 0, !7, i64 8, !7, i64 16}
!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 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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