; LLVM IR from einthomas/GVSPP :: vulkanutil.ll (ZN10VulkanUtil15createImageViewEP10VkDevice_TP9VkImage_T8VkFormatjj)

; 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.VkImageViewCreateInfo = type { i32, ptr, i32, ptr, i32, i32, %struct.VkComponentMapping, %struct.VkImageSubresourceRange }
%struct.VkComponentMapping = type { i32, i32, i32, i32 }
%struct.VkImageSubresourceRange = type { i32, i32, i32, i32, i32 }

@_ZTISt13runtime_error = external constant ptr
@.str.5 = external hidden unnamed_addr constant [37 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare ptr @__cxa_allocate_exception(i64)

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

declare void @__cxa_throw(ptr, ptr, ptr)

; 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 @_ZN10VulkanUtil15createImageViewEP10VkDevice_TP9VkImage_T8VkFormatjj(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #4 align 2 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.VkImageViewCreateInfo, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  store i32 %4, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 80, ptr %11) #5
  call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 80, i1 false)
  %15 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 0
  store i32 15, ptr %15, align 8, !tbaa !13
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 3
  store ptr %16, ptr %17, align 8, !tbaa !20
  %18 = load i32, ptr %10, align 4, !tbaa !11
  %19 = icmp ugt i32 %18, 1
  br i1 %19, label %20, label %22

20:                                               ; preds = %5
  %21 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 4
  store i32 5, ptr %21, align 8, !tbaa !21
  br label %24

22:                                               ; preds = %5
  %23 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 4
  store i32 1, ptr %23, align 8, !tbaa !21
  br label %24

24:                                               ; preds = %22, %20
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 5
  store i32 %25, ptr %26, align 4, !tbaa !22
  %27 = load i32, ptr %9, align 4, !tbaa !11
  %28 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 7
  %29 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %28, i32 0, i32 0
  store i32 %27, ptr %29, align 8, !tbaa !23
  %30 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 7
  %31 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %30, i32 0, i32 1
  store i32 0, ptr %31, align 4, !tbaa !24
  %32 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 7
  %33 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %32, i32 0, i32 2
  store i32 1, ptr %33, align 8, !tbaa !25
  %34 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 7
  %35 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %34, i32 0, i32 3
  store i32 0, ptr %35, align 4, !tbaa !26
  %36 = load i32, ptr %10, align 4, !tbaa !11
  %37 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %11, i32 0, i32 7
  %38 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %37, i32 0, i32 4
  store i32 %36, ptr %38, align 8, !tbaa !27
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call i32 @vkCreateImageView(ptr noundef %39, ptr noundef %11, ptr noundef null, ptr noundef %12)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %49

42:                                               ; preds = %24
  %43 = call ptr @__cxa_allocate_exception(i64 16) #5
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %43, ptr noundef @.str.5)
          to label %44 unwind label %45

44:                                               ; preds = %42
  call void @__cxa_throw(ptr %43, ptr @_ZTISt13runtime_error, ptr @_ZNSt13runtime_errorD1Ev) #6
  unreachable

45:                                               ; preds = %42
  %46 = landingpad { ptr, i32 }
          cleanup
  %47 = extractvalue { ptr, i32 } %46, 0
  store ptr %47, ptr %13, align 8
  %48 = extractvalue { ptr, i32 } %46, 1
  store i32 %48, ptr %14, align 4
  call void @__cxa_free_exception(ptr %43) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr %11) #5
  br label %51

49:                                               ; preds = %24
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr %11) #5
  ret ptr %50

51:                                               ; preds = %45
  %52 = load ptr, ptr %13, align 8
  %53 = load i32, ptr %14, align 4
  %54 = insertvalue { ptr, i32 } poison, ptr %52, 0
  %55 = insertvalue { ptr, i32 } %54, i32 %53, 1
  resume { ptr, i32 } %55
}

declare i32 @vkCreateImageView(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #4 = { 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 #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 = !{!"_ZTS8VkFormat", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS21VkImageViewCreateInfo", !15, i64 0, !6, i64 8, !12, i64 16, !6, i64 24, !16, i64 32, !10, i64 36, !17, i64 40, !19, i64 56}
!15 = !{!"_ZTS15VkStructureType", !7, i64 0}
!16 = !{!"_ZTS15VkImageViewType", !7, i64 0}
!17 = !{!"_ZTS18VkComponentMapping", !18, i64 0, !18, i64 4, !18, i64 8, !18, i64 12}
!18 = !{!"_ZTS18VkComponentSwizzle", !7, i64 0}
!19 = !{!"_ZTS23VkImageSubresourceRange", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!20 = !{!14, !6, i64 24}
!21 = !{!14, !16, i64 32}
!22 = !{!14, !10, i64 36}
!23 = !{!14, !12, i64 56}
!24 = !{!14, !12, i64 60}
!25 = !{!14, !12, i64 64}
!26 = !{!14, !12, i64 68}
!27 = !{!14, !12, i64 72}


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

%struct.VkImageViewCreateInfo = type { i32, ptr, i32, ptr, i32, i32, %struct.VkComponentMapping, %struct.VkImageSubresourceRange }
%struct.VkComponentMapping = type { i32, i32, i32, i32 }
%struct.VkImageSubresourceRange = type { i32, i32, i32, i32, i32 }

@_ZTISt13runtime_error = external constant ptr
@.str.5 = external hidden unnamed_addr constant [37 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

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

; 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 @_ZN10VulkanUtil15createImageViewEP10VkDevice_TP9VkImage_T8VkFormatjj(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %6 = alloca %struct.VkImageViewCreateInfo, align 8
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %6) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(80) %6, i8 0, i64 80, i1 false)
  store i32 15, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %1, ptr %8, align 8, !tbaa !17
  %9 = icmp ugt i32 %4, 1
  %spec.select = select i1 %9, i32 5, i32 1
  %10 = getelementptr inbounds i8, ptr %6, i64 32
  store i32 %spec.select, ptr %10, align 8
  %11 = getelementptr inbounds i8, ptr %6, i64 36
  store i32 %2, ptr %11, align 4, !tbaa !18
  %12 = getelementptr inbounds i8, ptr %6, i64 56
  store i32 %3, ptr %12, align 8, !tbaa !19
  %13 = getelementptr inbounds i8, ptr %6, i64 64
  store i32 1, ptr %13, align 8, !tbaa !20
  %14 = getelementptr inbounds i8, ptr %6, i64 72
  store i32 %4, ptr %14, align 8, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  %15 = call i32 @vkCreateImageView(ptr noundef %0, ptr noundef nonnull %6, ptr noundef null, ptr noundef nonnull %7)
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %21, label %16

16:                                               ; preds = %5
  %17 = call ptr @__cxa_allocate_exception(i64 16) #5
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef nonnull @.str.5)
          to label %18 unwind label %19

18:                                               ; preds = %16
  call void @__cxa_throw(ptr nonnull %17, ptr nonnull @_ZTISt13runtime_error, ptr nonnull @_ZNSt13runtime_errorD1Ev) #6
  unreachable

19:                                               ; preds = %16
  %20 = landingpad { ptr, i32 }
          cleanup
  call void @__cxa_free_exception(ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %6) #5
  resume { ptr, i32 } %20

21:                                               ; preds = %5
  %22 = load ptr, ptr %7, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %6) #5
  ret ptr %22
}

declare i32 @vkCreateImageView(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #4 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTS21VkImageViewCreateInfo", !7, i64 0, !10, i64 8, !11, i64 16, !10, i64 24, !12, i64 32, !13, i64 36, !14, i64 40, !16, i64 56}
!7 = !{!"_ZTS15VkStructureType", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_ZTS15VkImageViewType", !8, i64 0}
!13 = !{!"_ZTS8VkFormat", !8, i64 0}
!14 = !{!"_ZTS18VkComponentMapping", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12}
!15 = !{!"_ZTS18VkComponentSwizzle", !8, i64 0}
!16 = !{!"_ZTS23VkImageSubresourceRange", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16}
!17 = !{!6, !10, i64 24}
!18 = !{!6, !13, i64 36}
!19 = !{!6, !11, i64 56}
!20 = !{!6, !11, i64 64}
!21 = !{!6, !11, i64 72}
!22 = !{!10, !10, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass