; LLVM IR from blat-blatnik/Pocket-Universe :: src (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"

@glad_glDeleteShader = external global ptr, align 8
@glad_glCreateProgram = external global ptr, align 8
@glad_glAttachShader = external global ptr, align 8
@glad_glDeleteProgram = external global ptr, align 8
@glad_glDetachShader = external 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

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @linkShaderProgram(i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @loadComputeShader(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call i32 @loadShaderComponent(i32 noundef 37305, ptr noundef %8)
  store i32 %9, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %1
  %13 = load ptr, ptr @glad_glDeleteShader, align 8, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !9
  call void %13(i32 noundef %14)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %36

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load ptr, ptr @glad_glCreateProgram, align 8, !tbaa !5
  %17 = call i32 %16()
  store i32 %17, ptr %6, align 4, !tbaa !9
  %18 = load ptr, ptr @glad_glAttachShader, align 8, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load i32, ptr %4, align 4, !tbaa !9
  call void %18(i32 noundef %19, i32 noundef %20)
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = call zeroext i8 @linkShaderProgram(i32 noundef %21)
  store i8 %22, ptr %7, align 1, !tbaa !11
  %23 = load i8, ptr %7, align 1, !tbaa !11
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %28, label %25

25:                                               ; preds = %15
  %26 = load ptr, ptr @glad_glDeleteProgram, align 8, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !9
  call void %26(i32 noundef %27)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %35

28:                                               ; preds = %15
  %29 = load ptr, ptr @glad_glDetachShader, align 8, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = load i32, ptr %4, align 4, !tbaa !9
  call void %29(i32 noundef %30, i32 noundef %31)
  %32 = load ptr, ptr @glad_glDeleteShader, align 8, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !9
  call void %32(i32 noundef %33)
  %34 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %34, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %35

35:                                               ; preds = %28, %25
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %36

36:                                               ; preds = %35, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %37 = load i32, ptr %2, align 4
  ret i32 %37
}

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


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

@glad_glDeleteShader = external local_unnamed_addr global ptr, align 8
@glad_glCreateProgram = external local_unnamed_addr global ptr, align 8
@glad_glAttachShader = external local_unnamed_addr global ptr, align 8
@glad_glDeleteProgram = external local_unnamed_addr global ptr, align 8
@glad_glDetachShader = external local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @linkShaderProgram(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @loadComputeShader(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @loadShaderComponent(i32 noundef 37305, ptr noundef %0)
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %11, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr @glad_glCreateProgram, align 8, !tbaa !5
  %6 = tail call i32 %5() #1
  %7 = load ptr, ptr @glad_glAttachShader, align 8, !tbaa !5
  tail call void %7(i32 noundef %6, i32 noundef %2) #1
  %8 = tail call zeroext i8 @linkShaderProgram(i32 noundef %6)
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %11, label %9

9:                                                ; preds = %4
  %10 = load ptr, ptr @glad_glDetachShader, align 8, !tbaa !5
  tail call void %10(i32 noundef %6, i32 noundef %2) #1
  br label %11

11:                                               ; preds = %4, %1, %9
  %glad_glDeleteProgram.sink = phi ptr [ @glad_glDeleteShader, %9 ], [ @glad_glDeleteShader, %1 ], [ @glad_glDeleteProgram, %4 ]
  %.sink = phi i32 [ %2, %9 ], [ 0, %1 ], [ %6, %4 ]
  %.1 = phi i32 [ %6, %9 ], [ 0, %1 ], [ 0, %4 ]
  %12 = load ptr, ptr %glad_glDeleteProgram.sink, align 8, !tbaa !5
  tail call void %12(i32 noundef %.sink) #1
  ret i32 %.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 = { 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"}


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