; LLVM IR from jrouwe/JoltPhysics :: TestFramework/Renderer/VK/RenderPrimitiveVK.ll (ZN17RenderPrimitiveVK16LockVertexBufferEv)

; 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.JPH::AssertLastParam" = type { i8 }
%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", i32, i32, i32, i32, i32 }
%"class.JPH::RefTargetVirtual" = type { ptr }
%"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 }

@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [100 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 uwtable
define dso_local noundef ptr @_ZN17RenderPrimitiveVK16LockVertexBufferEv(ptr noundef nonnull align 8 dereferenceable(145) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %"struct.JPH::AssertLastParam", align 1
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  br label %6

6:                                                ; preds = %1
  %7 = getelementptr inbounds %class.RenderPrimitiveVK, ptr %5, i32 0, i32 3
  %8 = load i8, ptr %7, align 8, !tbaa !9, !range !20, !noundef !21
  %9 = trunc i8 %8 to i1
  br i1 %9, label %10, label %13

10:                                               ; preds = %6
  %11 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 42)
  br i1 %11, label %12, label %13

12:                                               ; preds = %10
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #5, !srcloc !22
  br label %13

13:                                               ; preds = %12, %10, %6
  br label %14

14:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %15 = getelementptr inbounds %class.RenderPrimitiveVK, ptr %5, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !23
  %17 = call noundef ptr @_ZNK10RendererVK9GetDeviceEv(ptr noundef nonnull align 16 dereferenceable(1936) %16)
  %18 = getelementptr inbounds %class.RenderPrimitiveVK, ptr %5, i32 0, i32 2
  %19 = getelementptr inbounds %class.BufferVK, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !24
  %21 = getelementptr inbounds %class.RenderPrimitiveVK, ptr %5, i32 0, i32 2
  %22 = getelementptr inbounds %class.BufferVK, ptr %21, i32 0, i32 2
  %23 = load i64, ptr %22, align 8, !tbaa !25
  %24 = getelementptr inbounds %class.RenderPrimitive, ptr %5, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !26
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %class.RenderPrimitive, ptr %5, i32 0, i32 4
  %28 = load i32, ptr %27, align 4, !tbaa !27
  %29 = sext i32 %28 to i64
  %30 = mul i64 %26, %29
  %31 = call i32 @vkMapMemory(ptr noundef %17, ptr noundef %20, i64 noundef %23, i64 noundef %30, i32 noundef 0, ptr noundef %4)
  call void @_Z18FatalErrorIfFailed8VkResult(i32 noundef %31)
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  ret ptr %32
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) #2

declare void @_Z18FatalErrorIfFailed8VkResult(i32 noundef) #3

declare i32 @vkMapMemory(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef, ptr noundef) #3

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

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 = { inlinehint 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 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 #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, !19, i64 88}
!10 = !{!"_ZTS17RenderPrimitiveVK", !11, i64 0, !6, i64 32, !17, i64 40, !19, i64 88, !17, i64 96, !19, i64 144}
!11 = !{!"_ZTS15RenderPrimitive", !12, i64 0, !13, i64 8, !16, i64 12, !16, i64 16, !16, i64 20, !16, i64 24, !16, i64 28}
!12 = !{!"_ZTSN3JPH16RefTargetVirtualE"}
!13 = !{!"_ZTSN3JPH9RefTargetI15RenderPrimitiveEE", !14, i64 0}
!14 = !{!"_ZTSSt6atomicIjE", !15, i64 0}
!15 = !{!"_ZTSSt13__atomic_baseIjE", !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTS8BufferVK", !6, i64 0, !6, i64 8, !18, i64 16, !18, i64 24, !16, i64 32, !16, i64 36, !18, i64 40}
!18 = !{!"long", !7, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{i64 2158613142}
!23 = !{!10, !6, i64 32}
!24 = !{!10, !6, i64 48}
!25 = !{!10, !18, i64 56}
!26 = !{!11, !16, i64 12}
!27 = !{!11, !16, i64 20}


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

@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [100 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 uwtable
define dso_local noundef ptr @_ZN17RenderPrimitiveVK16LockVertexBufferEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(145) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 88
  %4 = load i8, ptr %3, align 8, !tbaa !5, !range !19, !noundef !20
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %6, label %9

6:                                                ; preds = %1
  %7 = tail call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 42)
  br i1 %7, label %8, label %9

8:                                                ; preds = %6
  tail call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #5, !srcloc !21
  br label %9

9:                                                ; preds = %1, %6, %8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load ptr, ptr %10, align 8, !tbaa !22
  %12 = tail call noundef ptr @_ZNK10RendererVK9GetDeviceEv(ptr noundef nonnull align 16 dereferenceable(1936) %11)
  %13 = getelementptr inbounds i8, ptr %0, i64 48
  %14 = load ptr, ptr %13, align 8, !tbaa !23
  %15 = getelementptr inbounds i8, ptr %0, i64 56
  %16 = load i64, ptr %15, align 8, !tbaa !24
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !25
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %0, i64 20
  %21 = load i32, ptr %20, align 4, !tbaa !26
  %22 = sext i32 %21 to i64
  %23 = mul nsw i64 %22, %19
  %24 = call i32 @vkMapMemory(ptr noundef %12, ptr noundef %14, i64 noundef %16, i64 noundef %23, i32 noundef 0, ptr noundef nonnull %2)
  call void @_Z18FatalErrorIfFailed8VkResult(i32 noundef %24)
  %25 = load ptr, ptr %2, align 8, !tbaa !27
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret ptr %25
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @_Z18FatalErrorIfFailed8VkResult(i32 noundef) local_unnamed_addr #3

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

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

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 = { inlinehint 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 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 #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, !18, i64 88}
!6 = !{!"_ZTS17RenderPrimitiveVK", !7, i64 0, !15, i64 32, !16, i64 40, !18, i64 88, !16, i64 96, !18, i64 144}
!7 = !{!"_ZTS15RenderPrimitive", !8, i64 0, !9, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28}
!8 = !{!"_ZTSN3JPH16RefTargetVirtualE"}
!9 = !{!"_ZTSN3JPH9RefTargetI15RenderPrimitiveEE", !10, i64 0}
!10 = !{!"_ZTSSt6atomicIjE", !11, i64 0}
!11 = !{!"_ZTSSt13__atomic_baseIjE", !12, i64 0}
!12 = !{!"int", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"any pointer", !13, i64 0}
!16 = !{!"_ZTS8BufferVK", !15, i64 0, !15, i64 8, !17, i64 16, !17, i64 24, !12, i64 32, !12, i64 36, !17, i64 40}
!17 = !{!"long", !13, i64 0}
!18 = !{!"bool", !13, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{i64 2158613142}
!22 = !{!6, !15, i64 32}
!23 = !{!6, !15, i64 48}
!24 = !{!6, !17, i64 56}
!25 = !{!7, !12, i64 12}
!26 = !{!7, !12, i64 20}
!27 = !{!15, !15, i64 0}


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