; LLVM IR from jrouwe/JoltPhysics :: TestFramework/Renderer/VK (RenderInstancesVK)

; 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.RenderInstancesVK = type { %class.RenderInstances.base, ptr, %class.BufferVK }
%class.RenderInstances.base = type <{ ptr, %"class.JPH::RefTarget" }>
%"class.JPH::RefTarget" = type { %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }
%class.BufferVK = type { ptr, ptr, i64, i64, i32, i32, i64 }
%class.RenderPrimitiveVK = type <{ %class.RenderPrimitive, ptr, %class.BufferVK, i8, [7 x i8], %class.BufferVK, i8, [7 x i8] }>
%class.RenderPrimitive = type { %"class.JPH::RefTargetVirtual", %"class.JPH::RefTarget.13", i32, i32, i32, i32, i32 }
%"class.JPH::RefTargetVirtual" = type { ptr }
%"class.JPH::RefTarget.13" = type { %"struct.std::atomic" }

; 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 @_ZNK17RenderInstancesVK4DrawEP15RenderPrimitiveii(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca [2 x ptr], align 16
  %12 = alloca [2 x i64], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp sle i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  br label %58

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %18 = getelementptr inbounds %class.RenderInstancesVK, ptr %13, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = call noundef ptr @_ZN10RendererVK16GetCommandBufferEv(ptr noundef nonnull align 16 dereferenceable(1936) %19)
  store ptr %20, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %21, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #4
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.RenderPrimitiveVK, ptr %22, i32 0, i32 2
  %24 = getelementptr inbounds %class.BufferVK, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !19
  store ptr %25, ptr %11, align 8, !tbaa !5
  %26 = getelementptr inbounds ptr, ptr %11, i64 1
  %27 = getelementptr inbounds %class.RenderInstancesVK, ptr %13, i32 0, i32 2
  %28 = getelementptr inbounds %class.BufferVK, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !25
  store ptr %29, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 0, i64 16, i1 false)
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds [2 x ptr], ptr %11, i64 0, i64 0
  %32 = getelementptr inbounds [2 x i64], ptr %12, i64 0, i64 0
  call void @vkCmdBindVertexBuffers(ptr noundef %30, i32 noundef 0, i32 noundef 2, ptr noundef %31, ptr noundef %32)
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.RenderPrimitiveVK, ptr %33, i32 0, i32 5
  %35 = getelementptr inbounds %class.BufferVK, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !26
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %45

38:                                               ; preds = %17
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %class.RenderPrimitive, ptr %40, i32 0, i32 3
  %42 = load i32, ptr %41, align 8, !tbaa !27
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !9
  call void @vkCmdDraw(ptr noundef %39, i32 noundef %42, i32 noundef %43, i32 noundef 0, i32 noundef %44)
  br label %57

45:                                               ; preds = %17
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.RenderPrimitiveVK, ptr %47, i32 0, i32 5
  %49 = getelementptr inbounds %class.BufferVK, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !26
  call void @vkCmdBindIndexBuffer(ptr noundef %46, ptr noundef %50, i64 noundef 0, i32 noundef 1)
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %class.RenderPrimitive, ptr %52, i32 0, i32 6
  %54 = load i32, ptr %53, align 4, !tbaa !28
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = load i32, ptr %7, align 4, !tbaa !9
  call void @vkCmdDrawIndexed(ptr noundef %51, i32 noundef %54, i32 noundef %55, i32 noundef 0, i32 noundef 0, i32 noundef %56)
  br label %57

57:                                               ; preds = %45, %38
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %58

58:                                               ; preds = %57, %16
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN10RendererVK16GetCommandBufferEv(ptr noundef nonnull align 16 dereferenceable(1936)) #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare void @vkCmdBindVertexBuffers(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #3

declare void @vkCmdDraw(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #3

declare void @vkCmdBindIndexBuffer(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #3

declare void @vkCmdDrawIndexed(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS17RenderInstancesVK", !13, i64 0, !6, i64 16, !17, i64 24}
!13 = !{!"_ZTS15RenderInstances", !14, i64 8}
!14 = !{!"_ZTSN3JPH9RefTargetI15RenderInstancesEE", !15, i64 0}
!15 = !{!"_ZTSSt6atomicIjE", !16, i64 0}
!16 = !{!"_ZTSSt13__atomic_baseIjE", !10, i64 0}
!17 = !{!"_ZTS8BufferVK", !6, i64 0, !6, i64 8, !18, i64 16, !18, i64 24, !10, i64 32, !10, i64 36, !18, i64 40}
!18 = !{!"long", !7, i64 0}
!19 = !{!20, !6, i64 40}
!20 = !{!"_ZTS17RenderPrimitiveVK", !21, i64 0, !6, i64 32, !17, i64 40, !24, i64 88, !17, i64 96, !24, i64 144}
!21 = !{!"_ZTS15RenderPrimitive", !22, i64 0, !23, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!22 = !{!"_ZTSN3JPH16RefTargetVirtualE"}
!23 = !{!"_ZTSN3JPH9RefTargetI15RenderPrimitiveEE", !15, i64 0}
!24 = !{!"bool", !7, i64 0}
!25 = !{!12, !6, i64 24}
!26 = !{!20, !6, i64 96}
!27 = !{!21, !10, i64 16}
!28 = !{!21, !10, i64 28}


; 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 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 uwtable
define dso_local void @_ZNK17RenderInstancesVK4DrawEP15RenderPrimitiveii(ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca [2 x ptr], align 16
  %6 = alloca [2 x i64], align 16
  %7 = icmp slt i32 %3, 1
  br i1 %7, label %27, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call noundef ptr @_ZN10RendererVK16GetCommandBufferEv(ptr noundef nonnull align 16 dereferenceable(1936) %10)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %12 = getelementptr inbounds i8, ptr %1, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !17
  store ptr %13, ptr %5, align 16, !tbaa !23
  %14 = getelementptr inbounds i8, ptr %5, i64 8
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !24
  store ptr %16, ptr %14, align 8, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %6, i8 0, i64 16, i1 false)
  call void @vkCmdBindVertexBuffers(ptr noundef %11, i32 noundef 0, i32 noundef 2, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %17 = getelementptr inbounds i8, ptr %1, i64 96
  %18 = load ptr, ptr %17, align 8, !tbaa !25
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %23

20:                                               ; preds = %8
  %21 = getelementptr inbounds i8, ptr %1, i64 16
  %22 = load i32, ptr %21, align 8, !tbaa !26
  call void @vkCmdDraw(ptr noundef %11, i32 noundef %22, i32 noundef %3, i32 noundef 0, i32 noundef %2)
  br label %26

23:                                               ; preds = %8
  call void @vkCmdBindIndexBuffer(ptr noundef %11, ptr noundef nonnull %18, i64 noundef 0, i32 noundef 1)
  %24 = getelementptr inbounds i8, ptr %1, i64 28
  %25 = load i32, ptr %24, align 4, !tbaa !27
  call void @vkCmdDrawIndexed(ptr noundef %11, i32 noundef %25, i32 noundef %3, i32 noundef 0, i32 noundef 0, i32 noundef %2)
  br label %26

26:                                               ; preds = %23, %20
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  br label %27

27:                                               ; preds = %4, %26
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare void @vkCmdBindVertexBuffers(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @vkCmdDraw(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare void @vkCmdBindIndexBuffer(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

declare void @vkCmdDrawIndexed(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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, !14, i64 16}
!6 = !{!"_ZTS17RenderInstancesVK", !7, i64 0, !14, i64 16, !15, i64 24}
!7 = !{!"_ZTS15RenderInstances", !8, i64 8}
!8 = !{!"_ZTSN3JPH9RefTargetI15RenderInstancesEE", !9, i64 0}
!9 = !{!"_ZTSSt6atomicIjE", !10, i64 0}
!10 = !{!"_ZTSSt13__atomic_baseIjE", !11, i64 0}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"any pointer", !12, i64 0}
!15 = !{!"_ZTS8BufferVK", !14, i64 0, !14, i64 8, !16, i64 16, !16, i64 24, !11, i64 32, !11, i64 36, !16, i64 40}
!16 = !{!"long", !12, i64 0}
!17 = !{!18, !14, i64 40}
!18 = !{!"_ZTS17RenderPrimitiveVK", !19, i64 0, !14, i64 32, !15, i64 40, !22, i64 88, !15, i64 96, !22, i64 144}
!19 = !{!"_ZTS15RenderPrimitive", !20, i64 0, !21, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!20 = !{!"_ZTSN3JPH16RefTargetVirtualE"}
!21 = !{!"_ZTSN3JPH9RefTargetI15RenderPrimitiveEE", !9, i64 0}
!22 = !{!"bool", !12, i64 0}
!23 = !{!14, !14, i64 0}
!24 = !{!6, !14, i64 24}
!25 = !{!18, !14, i64 96}
!26 = !{!19, !11, i64 16}
!27 = !{!19, !11, i64 28}


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