; LLVM IR from paroj/gltut :: glsdk/glmesh/source/Draw.ll (ZN6glmesh4Draw14WriteAttributeEPKvmm)

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

%"class.glmesh::AttribDesc" = type { i32, i32, i32, i32 }
%"class.glmesh::Draw" = type { %"class.glmesh::VertexWriter", i32, i64, ptr, %"class.glmesh::StreamBuffer::Map", ptr, i64, i32, %"class.std::vector" }
%"class.glmesh::VertexWriter" = type { i64 }
%"class.glmesh::StreamBuffer::Map" = type { ptr, ptr, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@_ZTIN6glmesh28TooManyVerticesSentExceptionE = external dso_local constant { ptr, ptr, ptr }, align 8

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

declare i32 @__gxx_personality_v0(...)

; 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 noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56)) #1 align 2

declare ptr @__cxa_allocate_exception(i64)

declare void @__cxa_free_exception(ptr)

declare void @__cxa_throw(ptr, ptr, ptr)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6glmesh4Draw14WriteAttributeEPKvmm(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #2 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca %"class.glmesh::AttribDesc", align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  %14 = getelementptr inbounds %"class.glmesh::Draw", ptr %13, i32 0, i32 7
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %24

17:                                               ; preds = %4
  %18 = call ptr @__cxa_allocate_exception(i64 40) #5
  invoke void @_ZN6glmesh28TooManyVerticesSentExceptionC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %18)
          to label %19 unwind label %20

19:                                               ; preds = %17
  call void @__cxa_throw(ptr %18, ptr @_ZTIN6glmesh28TooManyVerticesSentExceptionE, ptr @_ZN6glmesh13DrawExceptionD2Ev) #6
  unreachable

20:                                               ; preds = %17
  %21 = landingpad { ptr, i32 }
          cleanup
  %22 = extractvalue { ptr, i32 } %21, 0
  store ptr %22, ptr %9, align 8
  %23 = extractvalue { ptr, i32 } %21, 1
  store i32 %23, ptr %10, align 4
  call void @__cxa_free_exception(ptr %18) #5
  br label %58

24:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #5
  %25 = getelementptr inbounds %"class.glmesh::Draw", ptr %13, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = call { i64, i64 } @_ZNK6glmesh12VertexFormat13GetAttribDescEm(ptr noundef nonnull align 8 dereferenceable(56) %26, i64 noundef %27)
  %29 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 0
  %30 = extractvalue { i64, i64 } %28, 0
  store i64 %30, ptr %29, align 4
  %31 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 1
  %32 = extractvalue { i64, i64 } %28, 1
  store i64 %32, ptr %31, align 4
  %33 = call noundef i32 @_ZNK6glmesh10AttribDesc16GetNumComponentsEv(ptr noundef nonnull align 4 dereferenceable(16) %12)
  %34 = zext i32 %33 to i64
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #5
  store i64 %34, ptr %11, align 8, !tbaa !9
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = call noundef ptr @_ZN6glmesh4Draw15GetPtrForAttribEm(ptr noundef nonnull align 8 dereferenceable(104) %13, i64 noundef %35)
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = mul i64 %38, %39
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %36, ptr align 1 %37, i64 %40, i1 false)
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = add i64 %41, 1
  %43 = getelementptr inbounds %"class.glmesh::Draw", ptr %13, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  %45 = call noundef i64 @_ZNK6glmesh12VertexFormat13GetNumAttribsEv(ptr noundef nonnull align 8 dereferenceable(56) %44)
  %46 = icmp eq i64 %42, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %24
  %48 = call noundef ptr @_ZN6glmesh4Draw21GetOutputPtrForVertexEv(ptr noundef nonnull align 8 dereferenceable(104) %13)
  %49 = getelementptr inbounds %"class.glmesh::Draw", ptr %13, i32 0, i32 8
  %50 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %49, i64 noundef 0) #5
  %51 = getelementptr inbounds %"class.glmesh::Draw", ptr %13, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !20
  %53 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %52)
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %48, ptr align 1 %50, i64 %53, i1 false)
  %54 = getelementptr inbounds %"class.glmesh::Draw", ptr %13, i32 0, i32 7
  %55 = load i32, ptr %54, align 8, !tbaa !11
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %54, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %47, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret void

58:                                               ; preds = %20
  %59 = load ptr, ptr %9, align 8
  %60 = load i32, ptr %10, align 4
  %61 = insertvalue { ptr, i32 } poison, ptr %59, 0
  %62 = insertvalue { ptr, i32 } %61, i32 %60, 1
  resume { ptr, i32 } %62
}

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

declare { i64, i64 } @_ZNK6glmesh12VertexFormat13GetAttribDescEm(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef) #3

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN6glmesh4Draw15GetPtrForAttribEm(ptr noundef nonnull align 8 dereferenceable(104), i64 noundef) #2 align 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) #4

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN6glmesh4Draw21GetOutputPtrForVertexEv(ptr noundef nonnull align 8 dereferenceable(104)) #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6glmesh13DrawExceptionD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1 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 = { "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 = { nounwind }
attributes #6 = { noreturn }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !14, i64 72}
!12 = !{!"_ZTSN6glmesh4DrawE", !13, i64 0, !14, i64 8, !10, i64 16, !6, i64 24, !15, i64 32, !6, i64 56, !10, i64 64, !14, i64 72, !16, i64 80}
!13 = !{!"_ZTSN6glmesh12VertexWriterINS_4DrawEEE", !10, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTSN6glmesh12StreamBuffer3MapE", !6, i64 0, !6, i64 8, !10, i64 16}
!16 = !{!"_ZTSSt6vectorIhSaIhEE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!12, !6, 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"

%"class.glmesh::AttribDesc" = type { i32, i32, i32, i32 }

@_ZTIN6glmesh28TooManyVerticesSentExceptionE = external dso_local constant { ptr, ptr, ptr }, align 8

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

declare i32 @__gxx_personality_v0(...)

; 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 noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1 align 2

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @__cxa_free_exception(ptr) local_unnamed_addr

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6glmesh4Draw14WriteAttributeEPKvmm(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr nocapture noundef readonly %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca %"class.glmesh::AttribDesc", align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %14

9:                                                ; preds = %4
  %10 = tail call ptr @__cxa_allocate_exception(i64 40) #5
  invoke void @_ZN6glmesh28TooManyVerticesSentExceptionC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %10)
          to label %11 unwind label %12

11:                                               ; preds = %9
  tail call void @__cxa_throw(ptr nonnull %10, ptr nonnull @_ZTIN6glmesh28TooManyVerticesSentExceptionE, ptr nonnull @_ZN6glmesh13DrawExceptionD2Ev) #6
  unreachable

12:                                               ; preds = %9
  %13 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %10) #5
  resume { ptr, i32 } %13

14:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %17 = tail call { i64, i64 } @_ZNK6glmesh12VertexFormat13GetAttribDescEm(ptr noundef nonnull align 8 dereferenceable(56) %16, i64 noundef %3)
  %18 = extractvalue { i64, i64 } %17, 0
  store i64 %18, ptr %5, align 8
  %19 = getelementptr inbounds i8, ptr %5, i64 8
  %20 = extractvalue { i64, i64 } %17, 1
  store i64 %20, ptr %19, align 8
  %21 = call noundef i32 @_ZNK6glmesh10AttribDesc16GetNumComponentsEv(ptr noundef nonnull align 4 dereferenceable(16) %5)
  %22 = zext i32 %21 to i64
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  %23 = call noundef ptr @_ZN6glmesh4Draw15GetPtrForAttribEm(ptr noundef nonnull align 8 dereferenceable(104) %0, i64 noundef %3)
  %24 = mul i64 %22, %2
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %23, ptr align 1 %1, i64 %24, i1 false)
  %25 = add i64 %3, 1
  %26 = load ptr, ptr %15, align 8, !tbaa !18
  %27 = call noundef i64 @_ZNK6glmesh12VertexFormat13GetNumAttribsEv(ptr noundef nonnull align 8 dereferenceable(56) %26)
  %28 = icmp eq i64 %25, %27
  br i1 %28, label %29, label %37

29:                                               ; preds = %14
  %30 = call noundef ptr @_ZN6glmesh4Draw21GetOutputPtrForVertexEv(ptr noundef nonnull align 8 dereferenceable(104) %0)
  %31 = getelementptr inbounds i8, ptr %0, i64 80
  %32 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt6vectorIhSaIhEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %31, i64 noundef 0) #5
  %33 = load ptr, ptr %15, align 8, !tbaa !18
  %34 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %33)
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %30, ptr nonnull align 1 %32, i64 %34, i1 false)
  %35 = load i32, ptr %6, align 8, !tbaa !5
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr %6, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %29, %14
  ret void
}

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

declare { i64, i64 } @_ZNK6glmesh12VertexFormat13GetAttribDescEm(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef) local_unnamed_addr #3

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

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

; Function Attrs: mustprogress 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 nounwind uwtable
declare dso_local noundef i64 @_ZNK6glmesh12VertexFormat13GetNumAttribsEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6glmesh13DrawExceptionD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1 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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { noreturn }

!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 72}
!6 = !{!"_ZTSN6glmesh4DrawE", !7, i64 0, !11, i64 8, !8, i64 16, !12, i64 24, !13, i64 32, !12, i64 56, !8, i64 64, !11, i64 72, !14, i64 80}
!7 = !{!"_ZTSN6glmesh12VertexWriterINS_4DrawEEE", !8, i64 0}
!8 = !{!"long", !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 = !{!"_ZTSN6glmesh12StreamBuffer3MapE", !12, i64 0, !12, i64 8, !8, i64 16}
!14 = !{!"_ZTSSt6vectorIhSaIhEE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !12, i64 0, !12, i64 8, !12, i64 16}
!18 = !{!6, !12, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass