; LLVM IR from PyCee/NUS_library :: src/render (NUS_image_view)

; 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.NUS_texture = type { ptr, ptr, i32, i32, i32, i32, i32, %struct.NUS_binding }
%struct.NUS_binding = type { ptr, ptr, ptr, i32 }
%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 }
%struct.NUS_image_view = type { ptr, %struct.NUS_binding }

@vkCreateImageView = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @nus_image_view_build(ptr noundef %0, ptr noundef byval(%struct.NUS_texture) align 8 %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.VkImageViewCreateInfo, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.NUS_binding, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 80, ptr %7) #4
  %10 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %7, i32 0, i32 0
  store i32 15, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %7, i32 0, i32 1
  store ptr null, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %7, i32 0, i32 2
  store i32 0, ptr %12, align 8, !tbaa !16
  %13 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %7, i32 0, i32 3
  %14 = getelementptr inbounds %struct.NUS_texture, ptr %1, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  store ptr %15, ptr %13, align 8, !tbaa !20
  %16 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %7, i32 0, i32 4
  store i32 1, ptr %16, align 8, !tbaa !21
  %17 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %7, i32 0, i32 5
  %18 = getelementptr inbounds %struct.NUS_texture, ptr %1, i32 0, i32 2
  %19 = load i32, ptr %18, align 8, !tbaa !22
  store i32 %19, ptr %17, align 4, !tbaa !23
  %20 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %7, i32 0, i32 6
  %21 = getelementptr inbounds %struct.VkComponentMapping, ptr %20, i32 0, i32 0
  store i32 0, ptr %21, align 8, !tbaa !24
  %22 = getelementptr inbounds %struct.VkComponentMapping, ptr %20, i32 0, i32 1
  store i32 0, ptr %22, align 4, !tbaa !25
  %23 = getelementptr inbounds %struct.VkComponentMapping, ptr %20, i32 0, i32 2
  store i32 0, ptr %23, align 8, !tbaa !26
  %24 = getelementptr inbounds %struct.VkComponentMapping, ptr %20, i32 0, i32 3
  store i32 0, ptr %24, align 4, !tbaa !27
  %25 = getelementptr inbounds %struct.VkImageViewCreateInfo, ptr %7, i32 0, i32 7
  %26 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %27, ptr %26, align 8, !tbaa !28
  %28 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %25, i32 0, i32 1
  store i32 0, ptr %28, align 4, !tbaa !29
  %29 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %25, i32 0, i32 2
  store i32 1, ptr %29, align 8, !tbaa !30
  %30 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %25, i32 0, i32 3
  store i32 0, ptr %30, align 4, !tbaa !31
  %31 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %25, i32 0, i32 4
  store i32 1, ptr %31, align 8, !tbaa !32
  %32 = load ptr, ptr @vkCreateImageView, align 8, !tbaa !5
  %33 = call ptr @nus_get_bound_device()
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.NUS_image_view, ptr %34, i32 0, i32 0
  %36 = call i32 %32(ptr noundef %33, ptr noundef %7, ptr noundef null, ptr noundef %35)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %3
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %8, align 4
  br label %43

40:                                               ; preds = %3
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.NUS_image_view, ptr %41, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #4
  call void @nus_get_binding(ptr dead_on_unwind writable sret(%struct.NUS_binding) align 8 %9)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %42, ptr align 8 %9, i64 32, i1 false), !tbaa.struct !33
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #4
  store i32 1, ptr %4, align 4
  store i32 1, ptr %8, align 4
  br label %43

43:                                               ; preds = %40, %38
  call void @llvm.lifetime.end.p0(i64 80, ptr %7) #4
  %44 = load i32, ptr %4, align 4
  ret i32 %44
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @nus_get_bound_device() #2

declare i32 @printf(ptr noundef, ...) #2

declare void @nus_get_binding(ptr dead_on_unwind writable sret(%struct.NUS_binding) align 8) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"VkImageViewCreateInfo", !10, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !13, i64 40, !14, i64 56}
!13 = !{!"VkComponentMapping", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!14 = !{!"VkImageSubresourceRange", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !10, i64 16}
!17 = !{!18, !6, i64 0}
!18 = !{!"NUS_texture", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !19, i64 40}
!19 = !{!"NUS_binding", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!20 = !{!12, !6, i64 24}
!21 = !{!12, !10, i64 32}
!22 = !{!18, !10, i64 16}
!23 = !{!12, !10, i64 36}
!24 = !{!13, !10, i64 0}
!25 = !{!13, !10, i64 4}
!26 = !{!13, !10, i64 8}
!27 = !{!13, !10, i64 12}
!28 = !{!14, !10, i64 0}
!29 = !{!14, !10, i64 4}
!30 = !{!14, !10, i64 8}
!31 = !{!14, !10, i64 12}
!32 = !{!14, !10, i64 16}
!33 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 4, !9}


; 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.NUS_texture = type { ptr, ptr, i32, i32, i32, i32, i32, %struct.NUS_binding }
%struct.NUS_binding = type { ptr, ptr, ptr, i32 }
%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 }

@vkCreateImageView = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nus_image_view_build(ptr noundef %0, ptr nocapture noundef readonly byval(%struct.NUS_texture) align 8 %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.VkImageViewCreateInfo, align 8
  %5 = alloca %struct.NUS_binding, align 8
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %4) #6
  store i32 15, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr null, ptr %6, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 0, ptr %7, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %4, i64 24
  %9 = load ptr, ptr %1, align 8, !tbaa !15
  store ptr %9, ptr %8, align 8, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %4, i64 32
  store i32 1, ptr %10, align 8, !tbaa !19
  %11 = getelementptr inbounds i8, ptr %4, i64 36
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = load i32, ptr %12, align 8, !tbaa !20
  store i32 %13, ptr %11, align 4, !tbaa !21
  %14 = getelementptr inbounds i8, ptr %4, i64 40
  %15 = getelementptr inbounds i8, ptr %4, i64 56
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %14, i8 0, i64 16, i1 false)
  store i32 %2, ptr %15, align 8, !tbaa !22
  %16 = getelementptr inbounds i8, ptr %4, i64 60
  store <4 x i32> <i32 0, i32 1, i32 0, i32 1>, ptr %16, align 4, !tbaa !23
  %17 = load ptr, ptr @vkCreateImageView, align 8, !tbaa !24
  %18 = tail call ptr @nus_get_bound_device() #6
  %19 = call i32 %17(ptr noundef %18, ptr noundef nonnull %4, ptr noundef null, ptr noundef %0) #6
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %22, label %20

20:                                               ; preds = %3
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %24

22:                                               ; preds = %3
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #6
  call void @nus_get_binding(ptr dead_on_unwind nonnull writable sret(%struct.NUS_binding) align 8 %5) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %23, ptr noundef nonnull align 8 dereferenceable(32) %5, i64 32, i1 false), !tbaa.struct !25
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #6
  br label %24

24:                                               ; preds = %22, %20
  %.0 = phi i32 [ 0, %20 ], [ 1, %22 ]
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %4) #6
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @nus_get_bound_device() local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

declare void @nus_get_binding(ptr dead_on_unwind writable sret(%struct.NUS_binding) align 8) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

attributes #0 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nofree 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"VkImageViewCreateInfo", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !7, i64 36, !11, i64 40, !12, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"VkComponentMapping", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!12 = !{!"VkImageSubresourceRange", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !7, i64 16}
!15 = !{!16, !10, i64 0}
!16 = !{!"NUS_texture", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !17, i64 40}
!17 = !{!"NUS_binding", !10, i64 0, !10, i64 8, !10, i64 16, !7, i64 24}
!18 = !{!6, !10, i64 24}
!19 = !{!6, !7, i64 32}
!20 = !{!16, !7, i64 16}
!21 = !{!6, !7, i64 36}
!22 = !{!12, !7, i64 0}
!23 = !{!7, !7, i64 0}
!24 = !{!10, !10, i64 0}
!25 = !{i64 0, i64 8, !24, i64 8, i64 8, !24, i64 16, i64 8, !24, i64 24, i64 4, !23}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass