; 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: nounwind uwtable
define dso_local i32 @loadShader(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i32 @loadShaderComponent(i32 noundef 35633, ptr noundef %11)
  store i32 %12, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i32 @loadShaderComponent(i32 noundef 35632, ptr noundef %13)
  store i32 %14, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %20, label %17

17:                                               ; preds = %2
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %17, %2
  %21 = load ptr, ptr @glad_glDeleteShader, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !9
  call void %21(i32 noundef %22)
  %23 = load ptr, ptr @glad_glDeleteShader, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  call void %23(i32 noundef %24)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %54

25:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %26 = load ptr, ptr @glad_glCreateProgram, align 8, !tbaa !5
  %27 = call i32 %26()
  store i32 %27, ptr %9, align 4, !tbaa !9
  %28 = load ptr, ptr @glad_glAttachShader, align 8, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  call void %28(i32 noundef %29, i32 noundef %30)
  %31 = load ptr, ptr @glad_glAttachShader, align 8, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !9
  call void %31(i32 noundef %32, i32 noundef %33)
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #2
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = call zeroext i8 @linkShaderProgram(i32 noundef %34)
  store i8 %35, ptr %10, align 1, !tbaa !11
  %36 = load i8, ptr %10, align 1, !tbaa !11
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %41, label %38

38:                                               ; preds = %25
  %39 = load ptr, ptr @glad_glDeleteProgram, align 8, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !9
  call void %39(i32 noundef %40)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %53

41:                                               ; preds = %25
  %42 = load ptr, ptr @glad_glDetachShader, align 8, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !9
  call void %42(i32 noundef %43, i32 noundef %44)
  %45 = load ptr, ptr @glad_glDetachShader, align 8, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  call void %45(i32 noundef %46, i32 noundef %47)
  %48 = load ptr, ptr @glad_glDeleteShader, align 8, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !9
  call void %48(i32 noundef %49)
  %50 = load ptr, ptr @glad_glDeleteShader, align 8, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !9
  call void %50(i32 noundef %51)
  %52 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %52, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %53

53:                                               ; preds = %41, %38
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %54

54:                                               ; preds = %53, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %55 = load i32, ptr %3, align 4
  ret i32 %55
}

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

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

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

; 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 = { 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
define dso_local noundef i32 @loadShader(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @loadShaderComponent(i32 noundef 35633, ptr noundef %0)
  %4 = tail call i32 @loadShaderComponent(i32 noundef 35632, ptr noundef %1)
  %5 = icmp eq i32 %3, 0
  %6 = icmp eq i32 %4, 0
  %or.cond = select i1 %5, i1 true, i1 %6
  br i1 %or.cond, label %.sink.split, label %7

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

13:                                               ; preds = %7
  %14 = load ptr, ptr @glad_glDetachShader, align 8, !tbaa !5
  tail call void %14(i32 noundef %9, i32 noundef %3) #1
  %15 = load ptr, ptr @glad_glDetachShader, align 8, !tbaa !5
  tail call void %15(i32 noundef %9, i32 noundef %4) #1
  br label %.sink.split

.sink.split:                                      ; preds = %2, %13
  %.1.ph = phi i32 [ %9, %13 ], [ 0, %2 ]
  %16 = load ptr, ptr @glad_glDeleteShader, align 8, !tbaa !5
  tail call void %16(i32 noundef %3) #1
  br label %17

17:                                               ; preds = %.sink.split, %7
  %glad_glDeleteProgram.sink = phi ptr [ @glad_glDeleteProgram, %7 ], [ @glad_glDeleteShader, %.sink.split ]
  %.sink = phi i32 [ %9, %7 ], [ %4, %.sink.split ]
  %.1 = phi i32 [ 0, %7 ], [ %.1.ph, %.sink.split ]
  %18 = load ptr, ptr %glad_glDeleteProgram.sink, align 8, !tbaa !5
  tail call void %18(i32 noundef %.sink) #1
  ret i32 %.1
}

; 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

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,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass