; LLVM IR from tyoma/agge :: src/agge.text (layout_builder)

; 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.agge::font_metrics" = type { float, float, float }
%"struct.agge::agge_vector" = type { float, float }
%"class.agge::layout_builder" = type { %"struct.agge::layout_builder::state", ptr, ptr, float, ptr, ptr, ptr }
%"struct.agge::layout_builder::state" = type { float, i32 }
%"class.agge::range" = type { i64, i64, ptr }
%"struct.agge::glyph_run" = type { %"class.agge::range", %"class.std::shared_ptr", %"struct.agge::agge_vector" }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

; 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: mustprogress uwtable
define dso_local void @_ZN4agge14layout_builder11begin_styleERKSt10shared_ptrINS_4fontEE(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.agge::font_metrics", align 4
  %6 = alloca { <2 x float>, float }, align 8
  %7 = alloca %"struct.agge::agge_vector", align 4
  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
  call void @llvm.lifetime.start.p0(i64 12, ptr %5) #7
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN4agge4fontELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %9) #7
  %11 = call { <2 x float>, float } @_ZNK4agge4font11get_metricsEv(ptr noundef nonnull align 8 dereferenceable(1172) %10)
  store { <2 x float>, float } %11, ptr %6, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 8 %6, i64 12, i1 false)
  %12 = getelementptr inbounds %"class.agge::layout_builder", ptr %8, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %"class.agge::range", ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds %"class.agge::layout_builder", ptr %8, i32 0, i32 0
  %17 = getelementptr inbounds %"struct.agge::layout_builder::state", ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !17
  %19 = zext i32 %18 to i64
  %20 = icmp ult i64 %15, %19
  br i1 %20, label %21, label %29

21:                                               ; preds = %2
  %22 = getelementptr inbounds %"class.agge::layout_builder", ptr %8, i32 0, i32 5
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %24 = getelementptr inbounds %"class.agge::layout_builder", ptr %8, i32 0, i32 0
  %25 = getelementptr inbounds %"struct.agge::layout_builder::state", ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !17
  %27 = call noundef nonnull align 8 dereferenceable(48) ptr @_ZN4agge12_GLOBAL__N_114duplicate_lastISt6vectorINS_9glyph_runESaIS3_EEjEERNT_10value_typeERS6_T0_(ptr noundef nonnull align 8 dereferenceable(24) %23, i32 noundef %26)
  %28 = getelementptr inbounds %"class.agge::layout_builder", ptr %8, i32 0, i32 1
  store ptr %27, ptr %28, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %21, %2
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.agge::layout_builder", ptr %8, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %"struct.agge::glyph_run", ptr %32, i32 0, i32 1
  %34 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt10shared_ptrIN4agge4fontEEaSERKS2_(ptr noundef nonnull align 8 dereferenceable(16) %33, ptr noundef nonnull align 8 dereferenceable(16) %30) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %35 = getelementptr inbounds %"class.agge::layout_builder", ptr %8, i32 0, i32 0
  %36 = getelementptr inbounds %"struct.agge::layout_builder::state", ptr %35, i32 0, i32 0
  %37 = load float, ptr %36, align 8, !tbaa !19
  %38 = call <2 x float> @_ZN4agge13create_vectorIfEENS_11agge_vectorIT_EES2_S2_(float noundef %37, float noundef 0.000000e+00)
  store <2 x float> %38, ptr %7, align 4
  %39 = getelementptr inbounds %"class.agge::layout_builder", ptr %8, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %"struct.agge::glyph_run", ptr %40, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %41, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  %42 = getelementptr inbounds %"struct.agge::font_metrics", ptr %5, i32 0, i32 0
  %43 = load float, ptr %42, align 4, !tbaa !22
  %44 = getelementptr inbounds %"struct.agge::font_metrics", ptr %5, i32 0, i32 1
  %45 = load float, ptr %44, align 4, !tbaa !24
  %46 = fadd float %43, %45
  %47 = getelementptr inbounds %"struct.agge::font_metrics", ptr %5, i32 0, i32 2
  %48 = load float, ptr %47, align 4, !tbaa !25
  %49 = fadd float %46, %48
  %50 = getelementptr inbounds %"class.agge::layout_builder", ptr %8, i32 0, i32 3
  store float %49, ptr %50, align 8, !tbaa !26
  call void @llvm.lifetime.end.p0(i64 12, ptr %5) #7
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIN4agge4fontELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) #2 align 2

declare { <2 x float>, float } @_ZNK4agge4font11get_metricsEv(ptr noundef nonnull align 8 dereferenceable(1172)) #3

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

; Function Attrs: mustprogress uwtable
declare hidden noundef nonnull align 8 dereferenceable(48) ptr @_ZN4agge12_GLOBAL__N_114duplicate_lastISt6vectorINS_9glyph_runESaIS3_EEjEERNT_10value_typeERS6_T0_(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt10shared_ptrIN4agge4fontEEaSERKS2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local <2 x float> @_ZN4agge13create_vectorIfEENS_11agge_vectorIT_EES2_S2_(float noundef, float noundef) #6

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { mustprogress 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { mustprogress 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 #6 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="64" "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 #7 = { 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++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTSN4agge14layout_builderE", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"_ZTSN4agge14layout_builder5stateE", !12, i64 0, !13, i64 4}
!12 = !{!"float", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"_ZTSN4agge5rangeIKNS_10pod_vectorINS_16positioned_glyphEEEEE", !16, i64 0, !16, i64 8, !6, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!10, !13, i64 4}
!18 = !{!10, !6, i64 40}
!19 = !{!10, !12, i64 0}
!20 = !{i64 0, i64 4, !21, i64 4, i64 4, !21}
!21 = !{!12, !12, i64 0}
!22 = !{!23, !12, i64 0}
!23 = !{!"_ZTSN4agge12font_metricsE", !12, i64 0, !12, i64 4, !12, i64 8}
!24 = !{!23, !12, i64 4}
!25 = !{!23, !12, i64 8}
!26 = !{!10, !12, i64 24}


; 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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4agge14layout_builder11begin_styleERKSt10shared_ptrINS_4fontEE(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIN4agge4fontELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %1) #5
  %4 = tail call { <2 x float>, float } @_ZNK4agge4font11get_metricsEv(ptr noundef nonnull align 8 dereferenceable(1172) %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i64, ptr %6, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !16
  %10 = zext i32 %9 to i64
  %11 = icmp ult i64 %7, %10
  br i1 %11, label %12, label %16

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = tail call noundef nonnull align 8 dereferenceable(48) ptr @_ZN4agge12_GLOBAL__N_114duplicate_lastISt6vectorINS_9glyph_runESaIS3_EEjEERNT_10value_typeERS6_T0_(ptr noundef nonnull align 8 dereferenceable(24) %14, i32 noundef %9)
  store ptr %15, ptr %5, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %12, %2
  %17 = phi ptr [ %15, %12 ], [ %6, %2 ]
  %.fca.1.extract = extractvalue { <2 x float>, float } %4, 1
  %.fca.0.extract = extractvalue { <2 x float>, float } %4, 0
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  %19 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt10shared_ptrIN4agge4fontEEaSERKS2_(ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef nonnull align 8 dereferenceable(16) %1) #5
  %20 = load float, ptr %0, align 8, !tbaa !18
  %21 = tail call <2 x float> @_ZN4agge13create_vectorIfEENS_11agge_vectorIT_EES2_S2_(float noundef %20, float noundef 0.000000e+00)
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 40
  store <2 x float> %21, ptr %23, align 8
  %shift = shufflevector <2 x float> %.fca.0.extract, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %24 = fadd <2 x float> %.fca.0.extract, %shift
  %25 = extractelement <2 x float> %24, i64 0
  %26 = fadd float %.fca.1.extract, %25
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  store float %26, ptr %27, align 8, !tbaa !19
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIN4agge4fontELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1 align 2

declare { <2 x float>, float } @_ZNK4agge4font11get_metricsEv(ptr noundef nonnull align 8 dereferenceable(1172)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare hidden noundef nonnull align 8 dereferenceable(48) ptr @_ZN4agge12_GLOBAL__N_114duplicate_lastISt6vectorINS_9glyph_runESaIS3_EEjEERNT_10value_typeERS6_T0_(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt10shared_ptrIN4agge4fontEEaSERKS2_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local <2 x float> @_ZN4agge13create_vectorIfEENS_11agge_vectorIT_EES2_S2_(float noundef, float noundef) local_unnamed_addr #4

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 #1 = { mustprogress 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 = { "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 = { mustprogress 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 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="64" "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, !12, i64 8}
!6 = !{!"_ZTSN4agge14layout_builderE", !7, i64 0, !12, i64 8, !12, i64 16, !8, i64 24, !12, i64 32, !12, i64 40, !12, i64 48}
!7 = !{!"_ZTSN4agge14layout_builder5stateE", !8, i64 0, !11, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTSN4agge5rangeIKNS_10pod_vectorINS_16positioned_glyphEEEEE", !15, i64 0, !15, i64 8, !12, i64 16}
!15 = !{!"long", !9, i64 0}
!16 = !{!6, !11, i64 4}
!17 = !{!6, !12, i64 40}
!18 = !{!6, !8, i64 0}
!19 = !{!6, !8, i64 24}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass,VectorCombinePass