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

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

@nus_unbind_binding = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [66 x i8], align 1
@vkCmdPipelineBarrier = external dso_local 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 @printf(ptr noundef, ...) #1

; 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) #2

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

declare void @nus_bind_binding(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @nus_cmd_texture_transition(ptr noundef byval(%struct.NUS_texture) align 8 %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.VkImageSubresourceRange, align 4
  %13 = alloca %struct.VkImageMemoryBarrier, align 8
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %14 = getelementptr inbounds %struct.NUS_texture, ptr %0, i32 0, i32 7
  call void @nus_bind_binding(ptr noundef %14)
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = call i32 @nus_texture_layout_to_mask(i32 noundef %15, ptr noundef %9)
  %17 = icmp ne i32 %16, 1
  br i1 %17, label %18, label %20

18:                                               ; preds = %4
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %54

20:                                               ; preds = %4
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = call i32 @nus_texture_layout_to_mask(i32 noundef %21, ptr noundef %10)
  %23 = icmp ne i32 %22, 1
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %54

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 20, ptr %12) #4
  %27 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %12, i32 0, i32 0
  %28 = getelementptr inbounds %struct.NUS_texture, ptr %0, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !11
  store i32 %29, ptr %27, align 4, !tbaa !14
  %30 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %12, i32 0, i32 1
  store i32 0, ptr %30, align 4, !tbaa !16
  %31 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %12, i32 0, i32 2
  store i32 1, ptr %31, align 4, !tbaa !17
  %32 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %12, i32 0, i32 3
  store i32 0, ptr %32, align 4, !tbaa !18
  %33 = getelementptr inbounds %struct.VkImageSubresourceRange, ptr %12, i32 0, i32 4
  store i32 1, ptr %33, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 72, ptr %13) #4
  %34 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 0
  store i32 45, ptr %34, align 8, !tbaa !20
  %35 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 1
  store ptr null, ptr %35, align 8, !tbaa !22
  %36 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 2
  %37 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %37, ptr %36, align 8, !tbaa !23
  %38 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 3
  %39 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %39, ptr %38, align 4, !tbaa !24
  %40 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 4
  %41 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %41, ptr %40, align 8, !tbaa !25
  %42 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 5
  %43 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %43, ptr %42, align 4, !tbaa !26
  %44 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 6
  store i32 -1, ptr %44, align 8, !tbaa !27
  %45 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 7
  store i32 -1, ptr %45, align 4, !tbaa !28
  %46 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 8
  %47 = getelementptr inbounds %struct.NUS_texture, ptr %0, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !29
  store ptr %48, ptr %46, align 8, !tbaa !30
  %49 = getelementptr inbounds %struct.VkImageMemoryBarrier, ptr %13, i32 0, i32 9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %49, ptr align 4 %12, i64 20, i1 false), !tbaa.struct !31
  %50 = load ptr, ptr @vkCmdPipelineBarrier, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  call void %50(ptr noundef %51, i32 noundef 1, i32 noundef 1, i32 noundef 0, i32 noundef 0, ptr noundef null, i32 noundef 0, ptr noundef null, i32 noundef 1, ptr noundef %13)
  %52 = load ptr, ptr @nus_unbind_binding, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.NUS_texture, ptr %0, i32 0, i32 7
  call void %52(ptr noundef %53)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 72, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 20, ptr %12) #4
  br label %54

54:                                               ; preds = %26, %24, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %55 = load i32, ptr %5, align 4
  ret i32 %55
}

; Function Attrs: nounwind uwtable
declare hidden i32 @nus_texture_layout_to_mask(i32 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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: readwrite) }
attributes #3 = { 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 }

!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 20}
!12 = !{!"NUS_texture", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !13, i64 40}
!13 = !{!"NUS_binding", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!14 = !{!15, !10, i64 0}
!15 = !{!"VkImageSubresourceRange", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!16 = !{!15, !10, i64 4}
!17 = !{!15, !10, i64 8}
!18 = !{!15, !10, i64 12}
!19 = !{!15, !10, i64 16}
!20 = !{!21, !10, i64 0}
!21 = !{!"VkImageMemoryBarrier", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !6, i64 40, !15, i64 48}
!22 = !{!21, !6, i64 8}
!23 = !{!21, !10, i64 16}
!24 = !{!21, !10, i64 20}
!25 = !{!21, !10, i64 24}
!26 = !{!21, !10, i64 28}
!27 = !{!21, !10, i64 32}
!28 = !{!21, !10, i64 36}
!29 = !{!12, !6, i64 0}
!30 = !{!21, !6, i64 40}
!31 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, 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.VkImageMemoryBarrier = type { i32, ptr, i32, i32, i32, i32, i32, i32, ptr, %struct.VkImageSubresourceRange }
%struct.VkImageSubresourceRange = type { i32, i32, i32, i32, i32 }

@nus_unbind_binding = external local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [66 x i8], align 1
@vkCmdPipelineBarrier = external dso_local 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

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

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

declare void @nus_bind_binding(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nus_cmd_texture_transition(ptr noundef byval(%struct.NUS_texture) align 8 %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #3 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.VkImageMemoryBarrier, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  call void @nus_bind_binding(ptr noundef nonnull %8) #4
  %9 = call i32 @nus_texture_layout_to_mask(i32 noundef %2, ptr noundef nonnull %5)
  %.not = icmp eq i32 %9, 1
  br i1 %.not, label %12, label %10

10:                                               ; preds = %4
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %33

12:                                               ; preds = %4
  %13 = call i32 @nus_texture_layout_to_mask(i32 noundef %3, ptr noundef nonnull %6)
  %.not5 = icmp eq i32 %13, 1
  br i1 %.not5, label %16, label %14

14:                                               ; preds = %12
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %33

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %0, i64 20
  %18 = load i32, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %7) #4
  store i32 45, ptr %7, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %7, i64 8
  store ptr null, ptr %19, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %7, i64 16
  %21 = load i32, ptr %5, align 4, !tbaa !16
  store i32 %21, ptr %20, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %7, i64 20
  %23 = load i32, ptr %6, align 4, !tbaa !16
  store i32 %23, ptr %22, align 4, !tbaa !18
  %24 = getelementptr inbounds i8, ptr %7, i64 24
  store i32 %2, ptr %24, align 8, !tbaa !19
  %25 = getelementptr inbounds i8, ptr %7, i64 28
  store i32 %3, ptr %25, align 4, !tbaa !20
  %26 = getelementptr inbounds i8, ptr %7, i64 32
  store i32 -1, ptr %26, align 8, !tbaa !21
  %27 = getelementptr inbounds i8, ptr %7, i64 36
  store i32 -1, ptr %27, align 4, !tbaa !22
  %28 = getelementptr inbounds i8, ptr %7, i64 40
  %29 = load ptr, ptr %0, align 8, !tbaa !23
  store ptr %29, ptr %28, align 8, !tbaa !24
  %30 = getelementptr inbounds i8, ptr %7, i64 48
  store i32 %18, ptr %30, align 8, !tbaa !16
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 52
  store <4 x i32> <i32 0, i32 1, i32 0, i32 1>, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !16
  %31 = load ptr, ptr @vkCmdPipelineBarrier, align 8, !tbaa !25
  call void %31(ptr noundef %1, i32 noundef 1, i32 noundef 1, i32 noundef 0, i32 noundef 0, ptr noundef null, i32 noundef 0, ptr noundef null, i32 noundef 1, ptr noundef nonnull %7) #4
  %32 = load ptr, ptr @nus_unbind_binding, align 8, !tbaa !25
  call void %32(ptr noundef nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %7) #4
  br label %33

33:                                               ; preds = %16, %14, %10
  %.0 = phi i32 [ 0, %10 ], [ 0, %14 ], [ 1, %16 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @nus_texture_layout_to_mask(i32 noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 }

!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, !10, i64 20}
!6 = !{!"NUS_texture", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !11, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"NUS_binding", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!12 = !{!13, !10, i64 0}
!13 = !{!"VkImageMemoryBarrier", !10, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !14, i64 48}
!14 = !{!"VkImageSubresourceRange", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!15 = !{!13, !7, i64 8}
!16 = !{!10, !10, i64 0}
!17 = !{!13, !10, i64 16}
!18 = !{!13, !10, i64 20}
!19 = !{!13, !10, i64 24}
!20 = !{!13, !10, i64 28}
!21 = !{!13, !10, i64 32}
!22 = !{!13, !10, i64 36}
!23 = !{!6, !7, i64 0}
!24 = !{!13, !7, i64 40}
!25 = !{!7, !7, i64 0}


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