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

; 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::VertexFormat::Enable" = type { ptr }
%"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 }

@_ZN2gl15BindVertexArrayE = external global ptr, align 8
@_ZN2gl10BindBufferE = external global ptr, align 8
@_ZN2gl10DrawArraysE = external global 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 uwtable
define dso_local noundef i32 @_ZN6glmesh4Draw14InternalRenderEv(ptr noundef nonnull align 8 dereferenceable(104) %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %"class.glmesh::VertexFormat::Enable", align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 7
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  br label %54

12:                                               ; preds = %1
  %13 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 4
  %14 = call noundef zeroext i1 @_ZN6glmesh12StreamBuffer3Map7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(24) %13)
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %2, align 4
  br label %54

16:                                               ; preds = %12
  %17 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 5
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  %19 = call noundef i32 @_ZN6glmesh12StreamBuffer6GetVaoEv(ptr noundef nonnull align 8 dereferenceable(32) %18)
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  %22 = load ptr, ptr @_ZN2gl15BindVertexArrayE, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  %25 = call noundef i32 @_ZN6glmesh12StreamBuffer6GetVaoEv(ptr noundef nonnull align 8 dereferenceable(32) %24)
  call void %22(i32 noundef %25)
  br label %26

26:                                               ; preds = %21, %16
  %27 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  %30 = call noundef i32 @_ZN6glmesh12StreamBuffer9GetBufferEv(ptr noundef nonnull align 8 dereferenceable(32) %29)
  call void %27(i32 noundef 34962, i32 noundef %30)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %31 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  %33 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 6
  %34 = load i64, ptr %33, align 8, !tbaa !21
  call void @_ZN6glmesh12VertexFormat6EnableC1ERKS0_m(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(56) %32, i64 noundef %34)
  %35 = load ptr, ptr @_ZN2gl10DrawArraysE, align 8, !tbaa !5
  %36 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !22
  %38 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 2
  %39 = load i64, ptr %38, align 8, !tbaa !23
  %40 = trunc i64 %39 to i32
  invoke void %35(i32 noundef %37, i32 noundef 0, i32 noundef %40)
          to label %41 unwind label %49

41:                                               ; preds = %26
  call void @_ZN6glmesh12VertexFormat6EnableD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %42 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !5
  call void %42(i32 noundef 34962, i32 noundef 0)
  %43 = getelementptr inbounds %"class.glmesh::Draw", ptr %7, i32 0, i32 5
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  %45 = call noundef i32 @_ZN6glmesh12StreamBuffer6GetVaoEv(ptr noundef nonnull align 8 dereferenceable(32) %44)
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %53

47:                                               ; preds = %41
  %48 = load ptr, ptr @_ZN2gl15BindVertexArrayE, align 8, !tbaa !5
  call void %48(i32 noundef 0)
  br label %53

49:                                               ; preds = %26
  %50 = landingpad { ptr, i32 }
          cleanup
  %51 = extractvalue { ptr, i32 } %50, 0
  store ptr %51, ptr %5, align 8
  %52 = extractvalue { ptr, i32 } %50, 1
  store i32 %52, ptr %6, align 4
  call void @_ZN6glmesh12VertexFormat6EnableD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %56

53:                                               ; preds = %47, %41
  store i32 0, ptr %2, align 4
  br label %54

54:                                               ; preds = %53, %15, %11
  %55 = load i32, ptr %2, align 4
  ret i32 %55

56:                                               ; preds = %49
  %57 = load ptr, ptr %5, align 8
  %58 = load i32, ptr %6, align 4
  %59 = insertvalue { ptr, i32 } poison, ptr %57, 0
  %60 = insertvalue { ptr, i32 } %59, i32 %58, 1
  resume { ptr, i32 } %60
}

declare noundef zeroext i1 @_ZN6glmesh12StreamBuffer3Map7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(24)) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6glmesh12StreamBuffer6GetVaoEv(ptr noundef nonnull align 8 dereferenceable(32)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6glmesh12StreamBuffer9GetBufferEv(ptr noundef nonnull align 8 dereferenceable(32)) #3 align 2

declare void @_ZN6glmesh12VertexFormat6EnableC1ERKS0_m(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(56), i64 noundef) unnamed_addr #2

; Function Attrs: nounwind
declare void @_ZN6glmesh12VertexFormat6EnableD1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 #4 = { nounwind "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !13, i64 72}
!10 = !{!"_ZTSN6glmesh4DrawE", !11, i64 0, !13, i64 8, !12, i64 16, !6, i64 24, !14, i64 32, !6, i64 56, !12, i64 64, !13, i64 72, !15, i64 80}
!11 = !{!"_ZTSN6glmesh12VertexWriterINS_4DrawEEE", !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSN6glmesh12StreamBuffer3MapE", !6, i64 0, !6, i64 8, !12, i64 16}
!15 = !{!"_ZTSSt6vectorIhSaIhEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIhSaIhEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIhSaIhEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!10, !6, i64 56}
!20 = !{!10, !6, i64 24}
!21 = !{!10, !12, i64 64}
!22 = !{!10, !13, i64 8}
!23 = !{!10, !12, i64 16}


; 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::VertexFormat::Enable" = type { ptr }

@_ZN2gl15BindVertexArrayE = external local_unnamed_addr global ptr, align 8
@_ZN2gl10BindBufferE = external local_unnamed_addr global ptr, align 8
@_ZN2gl10DrawArraysE = external local_unnamed_addr global 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 uwtable
define dso_local noundef range(i32 0, 3) i32 @_ZN6glmesh4Draw14InternalRenderEv(ptr noundef nonnull align 8 dereferenceable(104) %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.glmesh::VertexFormat::Enable", align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 72
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %38

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = tail call noundef zeroext i1 @_ZN6glmesh12StreamBuffer3Map7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(24) %6)
  br i1 %7, label %8, label %38

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  %10 = load ptr, ptr %9, align 8, !tbaa !18
  %11 = tail call noundef i32 @_ZN6glmesh12StreamBuffer6GetVaoEv(ptr noundef nonnull align 8 dereferenceable(32) %10)
  %.not3 = icmp eq i32 %11, 0
  br i1 %.not3, label %16, label %12

12:                                               ; preds = %8
  %13 = load ptr, ptr @_ZN2gl15BindVertexArrayE, align 8, !tbaa !19
  %14 = load ptr, ptr %9, align 8, !tbaa !18
  %15 = tail call noundef i32 @_ZN6glmesh12StreamBuffer6GetVaoEv(ptr noundef nonnull align 8 dereferenceable(32) %14)
  tail call void %13(i32 noundef %15)
  br label %16

16:                                               ; preds = %12, %8
  %17 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !19
  %18 = load ptr, ptr %9, align 8, !tbaa !18
  %19 = tail call noundef i32 @_ZN6glmesh12StreamBuffer9GetBufferEv(ptr noundef nonnull align 8 dereferenceable(32) %18)
  tail call void %17(i32 noundef 34962, i32 noundef %19)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %0, i64 64
  %23 = load i64, ptr %22, align 8, !tbaa !21
  call void @_ZN6glmesh12VertexFormat6EnableC1ERKS0_m(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(56) %21, i64 noundef %23)
  %24 = load ptr, ptr @_ZN2gl10DrawArraysE, align 8, !tbaa !19
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load i32, ptr %25, align 8, !tbaa !22
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  %28 = load i64, ptr %27, align 8, !tbaa !23
  %29 = trunc i64 %28 to i32
  invoke void %24(i32 noundef %26, i32 noundef 0, i32 noundef %29)
          to label %30 unwind label %36

30:                                               ; preds = %16
  call void @_ZN6glmesh12VertexFormat6EnableD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %31 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !19
  call void %31(i32 noundef 34962, i32 noundef 0)
  %32 = load ptr, ptr %9, align 8, !tbaa !18
  %33 = call noundef i32 @_ZN6glmesh12StreamBuffer6GetVaoEv(ptr noundef nonnull align 8 dereferenceable(32) %32)
  %.not4 = icmp eq i32 %33, 0
  br i1 %.not4, label %38, label %34

34:                                               ; preds = %30
  %35 = load ptr, ptr @_ZN2gl15BindVertexArrayE, align 8, !tbaa !19
  call void %35(i32 noundef 0)
  br label %38

36:                                               ; preds = %16
  %37 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6glmesh12VertexFormat6EnableD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  resume { ptr, i32 } %37

38:                                               ; preds = %30, %34, %5, %1
  %.0 = phi i32 [ 1, %1 ], [ 2, %5 ], [ 0, %34 ], [ 0, %30 ]
  ret i32 %.0
}

declare noundef zeroext i1 @_ZN6glmesh12StreamBuffer3Map7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6glmesh12StreamBuffer6GetVaoEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6glmesh12StreamBuffer9GetBufferEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3 align 2

declare void @_ZN6glmesh12VertexFormat6EnableC1ERKS0_m(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(56), i64 noundef) unnamed_addr #2

; Function Attrs: nounwind
declare void @_ZN6glmesh12VertexFormat6EnableD1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 #4 = { nounwind "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, !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 56}
!19 = !{!12, !12, i64 0}
!20 = !{!6, !12, i64 24}
!21 = !{!6, !8, i64 64}
!22 = !{!6, !11, i64 8}
!23 = !{!6, !8, i64 16}


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