; LLVM IR from paroj/gltut :: glsdk/glmesh/source/CpuDataWriter.ll (ZNK6glmesh13CpuDataWriter16TransferToBufferEjjj)

; 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::CpuDataWriter" = type { %"class.glmesh::VertexWriter", %"class.std::vector", %"class.std::vector", ptr, i64 }
%"class.glmesh::VertexWriter" = type { i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl" }
%"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl" = type { %"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<char, std::allocator<char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@_ZTIN6glmesh25IncompleteVertexExceptionE = external dso_local constant { ptr, ptr, ptr }, align 8
@_ZN2gl10GenBuffersE = external global ptr, align 8
@_ZN2gl10BindBufferE = external global ptr, align 8
@_ZN2gl10BufferDataE = external global ptr, align 8

declare i32 @__gxx_personality_v0(...)

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

declare ptr @__cxa_allocate_exception(i64)

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

declare void @__cxa_free_exception(ptr)

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

declare void @__cxa_throw(ptr, ptr, ptr)

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK6glmesh13CpuDataWriter16TransferToBufferEjjj(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  %12 = call noundef i64 @_ZNK6glmesh12VertexWriterINS_13CpuDataWriterEE13GetCurrAttribEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %21

14:                                               ; preds = %4
  %15 = call ptr @__cxa_allocate_exception(i64 40) #2
  invoke void @_ZN6glmesh25IncompleteVertexExceptionC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %15)
          to label %16 unwind label %17

16:                                               ; preds = %14
  call void @__cxa_throw(ptr %15, ptr @_ZTIN6glmesh25IncompleteVertexExceptionE, ptr @_ZN6glmesh16CpuDataExceptionD2Ev) #3
  unreachable

17:                                               ; preds = %14
  %18 = landingpad { ptr, i32 }
          cleanup
  %19 = extractvalue { ptr, i32 } %18, 0
  store ptr %19, ptr %9, align 8
  %20 = extractvalue { ptr, i32 } %18, 1
  store i32 %20, ptr %10, align 4
  call void @__cxa_free_exception(ptr %15) #2
  br label %40

21:                                               ; preds = %4
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %26, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr @_ZN2gl10GenBuffersE, align 8, !tbaa !5
  call void %25(i32 noundef 1, ptr noundef %8)
  br label %26

26:                                               ; preds = %24, %21
  %27 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = load i32, ptr %8, align 4, !tbaa !9
  call void %27(i32 noundef %28, i32 noundef %29)
  %30 = load ptr, ptr @_ZN2gl10BufferDataE, align 8, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = getelementptr inbounds %"class.glmesh::CpuDataWriter", ptr %11, i32 0, i32 2
  %33 = call noundef i64 @_ZNKSt6vectorIcSaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %32) #2
  %34 = getelementptr inbounds %"class.glmesh::CpuDataWriter", ptr %11, i32 0, i32 2
  %35 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt6vectorIcSaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %34, i64 noundef 0) #2
  %36 = load i32, ptr %7, align 4, !tbaa !9
  call void %30(i32 noundef %31, i64 noundef %33, ptr noundef %35, i32 noundef %36)
  %37 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !9
  call void %37(i32 noundef %38, i32 noundef 0)
  %39 = load i32, ptr %8, align 4, !tbaa !9
  ret i32 %39

40:                                               ; preds = %17
  %41 = load ptr, ptr %9, align 8
  %42 = load i32, ptr %10, align 4
  %43 = insertvalue { ptr, i32 } poison, ptr %41, 0
  %44 = insertvalue { ptr, i32 } %43, i32 %42, 1
  resume { ptr, i32 } %44
}

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

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

attributes #0 = { 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 #1 = { 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 #2 = { nounwind }
attributes #3 = { 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 = !{!"int", !7, i64 0}


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

@_ZTIN6glmesh25IncompleteVertexExceptionE = external dso_local constant { ptr, ptr, ptr }, align 8
@_ZN2gl10GenBuffersE = external local_unnamed_addr global ptr, align 8
@_ZN2gl10BindBufferE = external local_unnamed_addr global ptr, align 8
@_ZN2gl10BufferDataE = external local_unnamed_addr global ptr, align 8

declare i32 @__gxx_personality_v0(...)

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

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

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

declare void @__cxa_free_exception(ptr) local_unnamed_addr

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK6glmesh13CpuDataWriter16TransferToBufferEjjj(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca i32, align 4
  store i32 %3, ptr %5, align 4, !tbaa !5
  %6 = tail call noundef i64 @_ZNK6glmesh12VertexWriterINS_13CpuDataWriterEE13GetCurrAttribEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %12, label %7

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

9:                                                ; preds = %7
  tail call void @__cxa_throw(ptr nonnull %8, ptr nonnull @_ZTIN6glmesh25IncompleteVertexExceptionE, ptr nonnull @_ZN6glmesh16CpuDataExceptionD2Ev) #3
  unreachable

10:                                               ; preds = %7
  %11 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %8) #2
  resume { ptr, i32 } %11

12:                                               ; preds = %4
  %.not6 = icmp eq i32 %3, 0
  br i1 %.not6, label %13, label %15

13:                                               ; preds = %12
  %14 = load ptr, ptr @_ZN2gl10GenBuffersE, align 8, !tbaa !9
  call void %14(i32 noundef 1, ptr noundef nonnull %5)
  %.pre = load i32, ptr %5, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %13, %12
  %16 = phi i32 [ %.pre, %13 ], [ %3, %12 ]
  %17 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !9
  call void %17(i32 noundef %1, i32 noundef %16)
  %18 = load ptr, ptr @_ZN2gl10BufferDataE, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = call noundef i64 @_ZNKSt6vectorIcSaIcEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %19) #2
  %21 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNKSt6vectorIcSaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %19, i64 noundef 0) #2
  call void %18(i32 noundef %1, i64 noundef %20, ptr noundef nonnull %21, i32 noundef %2)
  %22 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !9
  call void %22(i32 noundef %1, i32 noundef 0)
  %23 = load i32, ptr %5, align 4, !tbaa !5
  ret i32 %23
}

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

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

attributes #0 = { 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 #1 = { 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 #2 = { nounwind }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass