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

; 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_absolute_path = type { [100 x i8] }
%struct.VkShaderModuleCreateInfo = type { i32, ptr, i32, i64, ptr }
%struct.NUS_binding = type { ptr, ptr, ptr, i32 }
%struct.NUS_shader = type { ptr, i32, %struct.NUS_binding }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [49 x i8], align 1
@vkCreateShaderModule = external dso_local global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @nus_shader_build(ptr noundef byval(%struct.NUS_absolute_path) align 8 %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %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 i32, align 4
  %12 = alloca %struct.VkShaderModuleCreateInfo, align 8
  %13 = alloca %struct.NUS_binding, align 8
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %14 = getelementptr inbounds %struct.NUS_absolute_path, ptr %0, i32 0, i32 0
  %15 = getelementptr inbounds [100 x i8], ptr %14, i64 0, i64 0
  %16 = call noalias ptr @fopen(ptr noundef %15, ptr noundef @.str)
  store ptr %16, ptr %10, align 8, !tbaa !9
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %22

18:                                               ; preds = %3
  %19 = getelementptr inbounds %struct.NUS_absolute_path, ptr %0, i32 0, i32 0
  %20 = getelementptr inbounds [100 x i8], ptr %19, i64 0, i64 0
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %20)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %80

22:                                               ; preds = %3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %28, %22
  %24 = load ptr, ptr %10, align 8, !tbaa !9
  %25 = call i32 @getc(ptr noundef %24)
  %26 = sext i32 %25 to i64
  %27 = icmp ne i64 %26, -1
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %8, align 4, !tbaa !5
  br label %23, !llvm.loop !11

31:                                               ; preds = %23
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = mul i64 1, %33
  %35 = call noalias ptr @malloc(i64 noundef %34) #6
  store ptr %35, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  call void @rewind(ptr noundef %36)
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %49, %31
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %52

41:                                               ; preds = %37
  %42 = load ptr, ptr %10, align 8, !tbaa !9
  %43 = call i32 @getc(ptr noundef %42)
  %44 = trunc i32 %43 to i8
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  store i8 %44, ptr %48, align 1, !tbaa !13
  br label %49

49:                                               ; preds = %41
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !5
  br label %37, !llvm.loop !14

52:                                               ; preds = %37
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = call i32 @fclose(ptr noundef %53)
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.NUS_shader, ptr %56, i32 0, i32 1
  store i32 %55, ptr %57, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 40, ptr %12) #5
  %58 = getelementptr inbounds %struct.VkShaderModuleCreateInfo, ptr %12, i32 0, i32 0
  store i32 16, ptr %58, align 8, !tbaa !18
  %59 = getelementptr inbounds %struct.VkShaderModuleCreateInfo, ptr %12, i32 0, i32 1
  store ptr null, ptr %59, align 8, !tbaa !21
  %60 = getelementptr inbounds %struct.VkShaderModuleCreateInfo, ptr %12, i32 0, i32 2
  store i32 0, ptr %60, align 8, !tbaa !22
  %61 = getelementptr inbounds %struct.VkShaderModuleCreateInfo, ptr %12, i32 0, i32 3
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  store i64 %63, ptr %61, align 8, !tbaa !23
  %64 = getelementptr inbounds %struct.VkShaderModuleCreateInfo, ptr %12, i32 0, i32 4
  %65 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %65, ptr %64, align 8, !tbaa !24
  %66 = load ptr, ptr @vkCreateShaderModule, align 8, !tbaa !9
  %67 = call ptr @nus_get_bound_device()
  %68 = load ptr, ptr %6, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.NUS_shader, ptr %68, i32 0, i32 0
  %70 = call i32 %66(ptr noundef %67, ptr noundef %12, ptr noundef null, ptr noundef %69)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %76

72:                                               ; preds = %52
  %73 = getelementptr inbounds %struct.NUS_absolute_path, ptr %0, i32 0, i32 0
  %74 = getelementptr inbounds [100 x i8], ptr %73, i64 0, i64 0
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %74)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %79

76:                                               ; preds = %52
  %77 = load ptr, ptr %6, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.NUS_shader, ptr %77, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #5
  call void @nus_get_binding(ptr dead_on_unwind writable sret(%struct.NUS_binding) align 8 %13)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %78, ptr align 8 %13, i64 32, i1 false), !tbaa.struct !25
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #5
  store i32 1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %79

79:                                               ; preds = %76, %72
  call void @llvm.lifetime.end.p0(i64 40, ptr %12) #5
  br label %80

80:                                               ; preds = %79, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  %81 = load i32, ptr %4, align 4
  ret i32 %81
}

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

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

declare i32 @getc(ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

declare void @rewind(ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

declare ptr @nus_get_bound_device() #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) #4

; 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 = { nounwind allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}
!15 = !{!16, !6, i64 8}
!16 = !{!"NUS_shader", !10, i64 0, !6, i64 8, !17, i64 16}
!17 = !{!"NUS_binding", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!18 = !{!19, !6, i64 0}
!19 = !{!"VkShaderModuleCreateInfo", !6, i64 0, !10, i64 8, !6, i64 16, !20, i64 24, !10, i64 32}
!20 = !{!"long", !7, i64 0}
!21 = !{!19, !10, i64 8}
!22 = !{!19, !6, i64 16}
!23 = !{!19, !20, i64 24}
!24 = !{!19, !10, i64 32}
!25 = !{i64 0, i64 8, !9, i64 8, i64 8, !9, i64 16, i64 8, !9, i64 24, i64 4, !5}


; 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_absolute_path = type { [100 x i8] }
%struct.VkShaderModuleCreateInfo = type { i32, ptr, i32, i64, ptr }
%struct.NUS_binding = type { ptr, ptr, ptr, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nus_shader_build(ptr noundef byval(%struct.NUS_absolute_path) align 8 %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.VkShaderModuleCreateInfo, align 8
  %5 = alloca %struct.NUS_binding, align 8
  %6 = call noalias ptr @fopen(ptr noundef nonnull %0, ptr noundef nonnull @.str)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %.preheader

8:                                                ; preds = %3
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull %0)
  br label %32

.preheader:                                       ; preds = %3, %.preheader
  %.018 = phi i32 [ %11, %.preheader ], [ 0, %3 ]
  %10 = tail call i32 @getc(ptr noundef nonnull %6)
  %.not = icmp eq i32 %10, -1
  %11 = add nuw nsw i32 %.018, 1
  br i1 %.not, label %12, label %.preheader, !llvm.loop !5

12:                                               ; preds = %.preheader
  %13 = zext nneg i32 %.018 to i64
  %14 = tail call noalias ptr @malloc(i64 noundef %13) #6
  tail call void @rewind(ptr noundef nonnull %6)
  %.not22 = icmp eq i32 %.018, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %12 ]
  %15 = tail call i32 @getc(ptr noundef nonnull %6)
  %16 = trunc i32 %15 to i8
  %17 = getelementptr inbounds i8, ptr %14, i64 %indvars.iv
  store i8 %16, ptr %17, align 1, !tbaa !7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %13
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %12
  %18 = tail call i32 @fclose(ptr noundef nonnull %6)
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %1, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #7
  store i32 16, ptr %4, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr null, ptr %20, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 0, ptr %21, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %4, i64 24
  store i64 %13, ptr %22, align 8, !tbaa !21
  %23 = getelementptr inbounds i8, ptr %4, i64 32
  store ptr %14, ptr %23, align 8, !tbaa !22
  %24 = load ptr, ptr @vkCreateShaderModule, align 8, !tbaa !23
  %25 = tail call ptr @nus_get_bound_device() #7
  %26 = call i32 %24(ptr noundef %25, ptr noundef nonnull %4, ptr noundef null, ptr noundef %2) #7
  %.not20 = icmp eq i32 %26, 0
  br i1 %.not20, label %29, label %27

27:                                               ; preds = %._crit_edge
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %0)
  br label %31

29:                                               ; preds = %._crit_edge
  %30 = getelementptr inbounds i8, ptr %2, i64 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #7
  call void @nus_get_binding(ptr dead_on_unwind nonnull writable sret(%struct.NUS_binding) align 8 %5) #7
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %30, ptr noundef nonnull align 8 dereferenceable(32) %5, i64 32, i1 false), !tbaa.struct !24
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #7
  br label %31

31:                                               ; preds = %29, %27
  %.0 = phi i32 [ 0, %27 ], [ 1, %29 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #7
  br label %32

32:                                               ; preds = %31, %8
  %.1 = phi i32 [ 0, %8 ], [ %.0, %31 ]
  ret i32 %.1
}

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @getc(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare void @rewind(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

declare ptr @nus_get_bound_device() local_unnamed_addr #4

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

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !6}
!11 = !{!12, !14, i64 8}
!12 = !{!"NUS_shader", !13, i64 0, !14, i64 8, !15, i64 16}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!"NUS_binding", !13, i64 0, !13, i64 8, !13, i64 16, !14, i64 24}
!16 = !{!17, !14, i64 0}
!17 = !{!"VkShaderModuleCreateInfo", !14, i64 0, !13, i64 8, !14, i64 16, !18, i64 24, !13, i64 32}
!18 = !{!"long", !8, i64 0}
!19 = !{!17, !13, i64 8}
!20 = !{!17, !14, i64 16}
!21 = !{!17, !18, i64 24}
!22 = !{!17, !13, i64 32}
!23 = !{!13, !13, i64 0}
!24 = !{i64 0, i64 8, !23, i64 8, i64 8, !23, i64 16, i64 8, !23, i64 24, i64 4, !25}
!25 = !{!14, !14, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass