; LLVM IR from ggml-org/ggml :: src/gguf.ll (Z17gguf_write_to_bufPK12gguf_contextRSt6vectorIaSaIaEEb)

; 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.gguf_writer = type { ptr }
%struct.gguf_context = type { i32, %"class.std::vector", %"class.std::vector.17", i64, i64, i64, ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<gguf_kv, std::allocator<gguf_kv>>::_Vector_impl" }
%"struct.std::_Vector_base<gguf_kv, std::allocator<gguf_kv>>::_Vector_impl" = type { %"struct.std::_Vector_base<gguf_kv, std::allocator<gguf_kv>>::_Vector_impl_data" }
%"struct.std::_Vector_base<gguf_kv, std::allocator<gguf_kv>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.17" = type { %"struct.std::_Vector_base.18" }
%"struct.std::_Vector_base.18" = type { %"struct.std::_Vector_base<gguf_tensor_info, std::allocator<gguf_tensor_info>>::_Vector_impl" }
%"struct.std::_Vector_base<gguf_tensor_info, std::allocator<gguf_tensor_info>>::_Vector_impl" = type { %"struct.std::_Vector_base<gguf_tensor_info, std::allocator<gguf_tensor_info>>::_Vector_impl_data" }
%"struct.std::_Vector_base<gguf_tensor_info, std::allocator<gguf_tensor_info>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@.str.16 = external hidden unnamed_addr constant [5 x i8], align 1

; 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 nounwind uwtable
declare dso_local i64 @gguf_get_n_kv(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(88) ptr @_ZNKSt6vectorI7gguf_kvSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i64 @gguf_get_n_tensors(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(344) ptr @_ZNKSt6vectorI16gguf_tensor_infoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z17gguf_write_to_bufPK12gguf_contextRSt6vectorIaSaIaEEb(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i1 noundef zeroext %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca %struct.gguf_writer, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %15 = zext i1 %2 to i8
  store i8 %15, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN11gguf_writerC2ERSt6vectorIaSaIaEE(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(24) %16)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i64 @gguf_get_n_kv(ptr noundef %17)
  store i64 %18, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call i64 @gguf_get_n_tensors(ptr noundef %19)
  store i64 %20, ptr %9, align 8, !tbaa !11
  call void @_ZNK11gguf_writer5writeIcEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 1 dereferenceable(1) @.str.16)
  call void @_ZNK11gguf_writer5writeIcEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 1 dereferenceable(1) getelementptr inbounds ([5 x i8], ptr @.str.16, i64 0, i64 1))
  call void @_ZNK11gguf_writer5writeIcEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 1 dereferenceable(1) getelementptr inbounds ([5 x i8], ptr @.str.16, i64 0, i64 2))
  call void @_ZNK11gguf_writer5writeIcEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 1 dereferenceable(1) getelementptr inbounds ([5 x i8], ptr @.str.16, i64 0, i64 3))
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gguf_context, ptr %21, i32 0, i32 0
  call void @_ZNK11gguf_writer5writeIjEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 4 dereferenceable(4) %22)
  call void @_ZNK11gguf_writer5writeIlEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %9)
  call void @_ZNK11gguf_writer5writeIlEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %33, %3
  %24 = load i64, ptr %10, align 8, !tbaa !11
  %25 = load i64, ptr %8, align 8, !tbaa !11
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %36

28:                                               ; preds = %23
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gguf_context, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %10, align 8, !tbaa !11
  %32 = call noundef nonnull align 8 dereferenceable(88) ptr @_ZNKSt6vectorI7gguf_kvSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %31) #3
  call void @_ZNK11gguf_writer5writeERK7gguf_kv(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(88) %32)
  br label %33

33:                                               ; preds = %28
  %34 = load i64, ptr %10, align 8, !tbaa !11
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %10, align 8, !tbaa !11
  br label %23, !llvm.loop !13

36:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %47, %36
  %38 = load i64, ptr %11, align 8, !tbaa !11
  %39 = load i64, ptr %9, align 8, !tbaa !11
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %50

42:                                               ; preds = %37
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gguf_context, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %11, align 8, !tbaa !11
  %46 = call noundef nonnull align 8 dereferenceable(344) ptr @_ZNKSt6vectorI16gguf_tensor_infoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %44, i64 noundef %45) #3
  call void @_ZNK11gguf_writer17write_tensor_metaERK16gguf_tensor_info(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(344) %46)
  br label %47

47:                                               ; preds = %42
  %48 = load i64, ptr %11, align 8, !tbaa !11
  %49 = add nsw i64 %48, 1
  store i64 %49, ptr %11, align 8, !tbaa !11
  br label %37, !llvm.loop !15

50:                                               ; preds = %41
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.gguf_context, ptr %51, i32 0, i32 3
  %53 = load i64, ptr %52, align 8, !tbaa !16
  call void @_ZNK11gguf_writer3padEm(ptr noundef nonnull align 8 dereferenceable(8) %7, i64 noundef %53)
  %54 = load i8, ptr %6, align 1, !tbaa !9, !range !27, !noundef !28
  %55 = trunc i8 %54 to i1
  br i1 %55, label %56, label %57

56:                                               ; preds = %50
  store i32 1, ptr %12, align 4
  br label %79

57:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %58 = getelementptr inbounds %struct.gguf_writer, ptr %7, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !29
  %60 = call noundef i64 @_ZNKSt6vectorIaSaIaEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %59) #3
  store i64 %60, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store i64 0, ptr %14, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %75, %57
  %62 = load i64, ptr %14, align 8, !tbaa !11
  %63 = load i64, ptr %9, align 8, !tbaa !11
  %64 = icmp slt i64 %62, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %61
  store i32 8, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %78

66:                                               ; preds = %61
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.gguf_context, ptr %67, i32 0, i32 2
  %69 = load i64, ptr %14, align 8, !tbaa !11
  %70 = call noundef nonnull align 8 dereferenceable(344) ptr @_ZNKSt6vectorI16gguf_tensor_infoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %68, i64 noundef %69) #3
  %71 = load i64, ptr %13, align 8, !tbaa !11
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.gguf_context, ptr %72, i32 0, i32 3
  %74 = load i64, ptr %73, align 8, !tbaa !16
  call void @_ZNK11gguf_writer17write_tensor_dataERK16gguf_tensor_infomm(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(344) %70, i64 noundef %71, i64 noundef %74)
  br label %75

75:                                               ; preds = %66
  %76 = load i64, ptr %14, align 8, !tbaa !11
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %14, align 8, !tbaa !11
  br label %61, !llvm.loop !31

78:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  store i32 0, ptr %12, align 4
  br label %79

79:                                               ; preds = %78, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %80 = load i32, ptr %12, align 4
  switch i32 %80, label %82 [
    i32 0, label %81
    i32 1, label %81
  ]

81:                                               ; preds = %79, %79
  ret void

82:                                               ; preds = %79
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11gguf_writerC2ERSt6vectorIaSaIaEE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer5writeIcEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 1 dereferenceable(1)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer5writeIjEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4)) #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer5writeERK7gguf_kv(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(88)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer17write_tensor_metaERK16gguf_tensor_info(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(344)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer3padEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer17write_tensor_dataERK16gguf_tensor_infomm(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(344), i64 noundef, i64 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !12, i64 56}
!17 = !{!"_ZTS12gguf_context", !18, i64 0, !19, i64 8, !23, i64 32, !12, i64 56, !12, i64 64, !12, i64 72, !6, i64 80}
!18 = !{!"int", !7, i64 0}
!19 = !{!"_ZTSSt6vectorI7gguf_kvSaIS0_EE", !20, i64 0}
!20 = !{!"_ZTSSt12_Vector_baseI7gguf_kvSaIS0_EE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseI7gguf_kvSaIS0_EE12_Vector_implE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseI7gguf_kvSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!23 = !{!"_ZTSSt6vectorI16gguf_tensor_infoSaIS0_EE", !24, i64 0}
!24 = !{!"_ZTSSt12_Vector_baseI16gguf_tensor_infoSaIS0_EE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseI16gguf_tensor_infoSaIS0_EE12_Vector_implE", !26, i64 0}
!26 = !{!"_ZTSNSt12_Vector_baseI16gguf_tensor_infoSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!27 = !{i8 0, i8 2}
!28 = !{}
!29 = !{!30, !6, i64 0}
!30 = !{!"_ZTS11gguf_writer", !6, i64 0}
!31 = distinct !{!31, !14}


; 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.gguf_writer = type { ptr }

@.str.16 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i64 @gguf_get_n_kv(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(88) ptr @_ZNKSt6vectorI7gguf_kvSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i64 @gguf_get_n_tensors(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(344) ptr @_ZNKSt6vectorI16gguf_tensor_infoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z17gguf_write_to_bufPK12gguf_contextRSt6vectorIaSaIaEEb(ptr noundef %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i1 noundef zeroext %2) local_unnamed_addr #2 {
  %4 = alloca %struct.gguf_writer, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @_ZN11gguf_writerC2ERSt6vectorIaSaIaEE(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(24) %1)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %7 = call i64 @gguf_get_n_kv(ptr noundef %0)
  store i64 %7, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %8 = call i64 @gguf_get_n_tensors(ptr noundef %0)
  store i64 %8, ptr %6, align 8, !tbaa !5
  call void @_ZNK11gguf_writer5writeIcEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 1 dereferenceable(1) @.str.16)
  call void @_ZNK11gguf_writer5writeIcEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 1 dereferenceable(1) getelementptr inbounds (i8, ptr @.str.16, i64 1))
  call void @_ZNK11gguf_writer5writeIcEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 1 dereferenceable(1) getelementptr inbounds (i8, ptr @.str.16, i64 2))
  call void @_ZNK11gguf_writer5writeIcEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 1 dereferenceable(1) getelementptr inbounds (i8, ptr @.str.16, i64 3))
  call void @_ZNK11gguf_writer5writeIjEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(4) %0)
  call void @_ZNK11gguf_writer5writeIlEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %6)
  call void @_ZNK11gguf_writer5writeIlEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %9 = load i64, ptr %5, align 8, !tbaa !5
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %3
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  br label %15

.preheader:                                       ; preds = %15, %3
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %.lr.ph23, label %._crit_edge

.lr.ph23:                                         ; preds = %.preheader
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  br label %22

15:                                               ; preds = %.lr.ph, %15
  %.01921 = phi i64 [ 0, %.lr.ph ], [ %17, %15 ]
  %16 = call noundef nonnull align 8 dereferenceable(88) ptr @_ZNKSt6vectorI7gguf_kvSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %.01921) #3
  call void @_ZNK11gguf_writer5writeERK7gguf_kv(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(88) %16)
  %17 = add nuw nsw i64 %.01921, 1
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = icmp slt i64 %17, %18
  br i1 %19, label %15, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %22, %.preheader
  %20 = getelementptr inbounds i8, ptr %0, i64 56
  %21 = load i64, ptr %20, align 8, !tbaa !11
  call void @_ZNK11gguf_writer3padEm(ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef %21)
  br i1 %2, label %.loopexit, label %27

22:                                               ; preds = %.lr.ph23, %22
  %.02022 = phi i64 [ 0, %.lr.ph23 ], [ %24, %22 ]
  %23 = call noundef nonnull align 8 dereferenceable(344) ptr @_ZNKSt6vectorI16gguf_tensor_infoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %14, i64 noundef %.02022) #3
  call void @_ZNK11gguf_writer17write_tensor_metaERK16gguf_tensor_info(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(344) %23)
  %24 = add nuw nsw i64 %.02022, 1
  %25 = load i64, ptr %6, align 8, !tbaa !5
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %22, label %._crit_edge, !llvm.loop !23

27:                                               ; preds = %._crit_edge
  %28 = load ptr, ptr %4, align 8, !tbaa !24
  %29 = call noundef i64 @_ZNKSt6vectorIaSaIaEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %28) #3
  %30 = load i64, ptr %6, align 8, !tbaa !5
  %31 = icmp sgt i64 %30, 0
  br i1 %31, label %.lr.ph26, label %.loopexit

.lr.ph26:                                         ; preds = %27
  %32 = getelementptr inbounds i8, ptr %0, i64 32
  br label %33

33:                                               ; preds = %.lr.ph26, %33
  %.024 = phi i64 [ 0, %.lr.ph26 ], [ %36, %33 ]
  %34 = call noundef nonnull align 8 dereferenceable(344) ptr @_ZNKSt6vectorI16gguf_tensor_infoSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %32, i64 noundef %.024) #3
  %35 = load i64, ptr %20, align 8, !tbaa !11
  call void @_ZNK11gguf_writer17write_tensor_dataERK16gguf_tensor_infomm(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(344) %34, i64 noundef %29, i64 noundef %35)
  %36 = add nuw nsw i64 %.024, 1
  %37 = load i64, ptr %6, align 8, !tbaa !5
  %38 = icmp slt i64 %36, %37
  br i1 %38, label %33, label %.loopexit, !llvm.loop !26

.loopexit:                                        ; preds = %33, %27, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11gguf_writerC2ERSt6vectorIaSaIaEE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer5writeIjEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer5writeIlEEvRKT_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer5writeERK7gguf_kv(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(88)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer17write_tensor_metaERK16gguf_tensor_info(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(344)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer3padEm(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK11gguf_writer17write_tensor_dataERK16gguf_tensor_infomm(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(344), i64 noundef, i64 noundef) local_unnamed_addr #2 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 56}
!12 = !{!"_ZTS12gguf_context", !13, i64 0, !14, i64 8, !19, i64 32, !6, i64 56, !6, i64 64, !6, i64 72, !18, i64 80}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSSt6vectorI7gguf_kvSaIS0_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseI7gguf_kvSaIS0_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseI7gguf_kvSaIS0_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseI7gguf_kvSaIS0_EE17_Vector_impl_dataE", !18, i64 0, !18, i64 8, !18, i64 16}
!18 = !{!"any pointer", !7, i64 0}
!19 = !{!"_ZTSSt6vectorI16gguf_tensor_infoSaIS0_EE", !20, i64 0}
!20 = !{!"_ZTSSt12_Vector_baseI16gguf_tensor_infoSaIS0_EE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseI16gguf_tensor_infoSaIS0_EE12_Vector_implE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseI16gguf_tensor_infoSaIS0_EE17_Vector_impl_dataE", !18, i64 0, !18, i64 8, !18, i64 16}
!23 = distinct !{!23, !10}
!24 = !{!25, !18, i64 0}
!25 = !{!"_ZTS11gguf_writer", !18, i64 0}
!26 = distinct !{!26, !10}


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