; LLVM IR from brenocq/atta :: src/extern/glad/src (egl)

; 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_eglGetCurrentDisplay = external dso_local global ptr, align 8
@glad_eglGetDisplay = external dso_local global ptr, align 8
@glad_eglGetError = external dso_local global ptr, align 8
@glad_eglQueryString = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @gladLoadEGLUserPtr(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = call ptr %10(ptr noundef %11, ptr noundef @.str)
  store ptr %12, ptr @glad_eglGetDisplay, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = call ptr %13(ptr noundef %14, ptr noundef @.str.1)
  store ptr %15, ptr @glad_eglGetCurrentDisplay, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call ptr %16(ptr noundef %17, ptr noundef @.str.2)
  store ptr %18, ptr @glad_eglQueryString, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = call ptr %19(ptr noundef %20, ptr noundef @.str.3)
  store ptr %21, ptr @glad_eglGetError, align 8, !tbaa !5
  %22 = load ptr, ptr @glad_eglGetDisplay, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %33, label %24

24:                                               ; preds = %3
  %25 = load ptr, ptr @glad_eglGetCurrentDisplay, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %33, label %27

27:                                               ; preds = %24
  %28 = load ptr, ptr @glad_eglQueryString, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %33, label %30

30:                                               ; preds = %27
  %31 = load ptr, ptr @glad_eglGetError, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %30, %27, %24, %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %57

34:                                               ; preds = %30
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i32 @glad_egl_find_core_egl(ptr noundef %35)
  store i32 %36, ptr %8, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %40, label %39

39:                                               ; preds = %34
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %57

40:                                               ; preds = %34
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  call void @glad_egl_load_EGL_VERSION_1_0(ptr noundef %41, ptr noundef %42)
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  call void @glad_egl_load_EGL_VERSION_1_1(ptr noundef %43, ptr noundef %44)
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  call void @glad_egl_load_EGL_VERSION_1_2(ptr noundef %45, ptr noundef %46)
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  call void @glad_egl_load_EGL_VERSION_1_4(ptr noundef %47, ptr noundef %48)
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  call void @glad_egl_load_EGL_VERSION_1_5(ptr noundef %49, ptr noundef %50)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call i32 @glad_egl_find_extensions_egl(ptr noundef %51)
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %55, label %54

54:                                               ; preds = %40
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %57

55:                                               ; preds = %40
  %56 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %56, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %57

57:                                               ; preds = %55, %54, %39, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %58 = load i32, ptr %4, align 4
  ret i32 %58
}

; 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 @glad_egl_find_core_egl(ptr noundef) #0

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @glad_egl_find_extensions_egl(ptr 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}


; 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_eglGetCurrentDisplay = external dso_local local_unnamed_addr global ptr, align 8
@glad_eglGetDisplay = external dso_local local_unnamed_addr global ptr, align 8
@glad_eglGetError = external dso_local local_unnamed_addr global ptr, align 8
@glad_eglQueryString = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @gladLoadEGLUserPtr(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr %1(ptr noundef %2, ptr noundef nonnull @.str) #1
  store ptr %4, ptr @glad_eglGetDisplay, align 8, !tbaa !5
  %5 = tail call ptr %1(ptr noundef %2, ptr noundef nonnull @.str.1) #1
  store ptr %5, ptr @glad_eglGetCurrentDisplay, align 8, !tbaa !5
  %6 = tail call ptr %1(ptr noundef %2, ptr noundef nonnull @.str.2) #1
  store ptr %6, ptr @glad_eglQueryString, align 8, !tbaa !5
  %7 = tail call ptr %1(ptr noundef %2, ptr noundef nonnull @.str.3) #1
  store ptr %7, ptr @glad_eglGetError, align 8, !tbaa !5
  %8 = load ptr, ptr @glad_eglGetDisplay, align 8, !tbaa !5
  %9 = load ptr, ptr @glad_eglGetCurrentDisplay, align 8
  %10 = load ptr, ptr @glad_eglQueryString, align 8
  %11 = insertelement <4 x ptr> poison, ptr %8, i64 0
  %12 = insertelement <4 x ptr> %11, ptr %9, i64 1
  %13 = insertelement <4 x ptr> %12, ptr %10, i64 2
  %14 = insertelement <4 x ptr> %13, ptr %7, i64 3
  %.fr = freeze <4 x ptr> %14
  %15 = icmp eq <4 x ptr> %.fr, zeroinitializer
  %16 = bitcast <4 x i1> %15 to i4
  %.not29 = icmp eq i4 %16, 0
  br i1 %.not29, label %17, label %21

17:                                               ; preds = %3
  %18 = tail call i32 @glad_egl_find_core_egl(ptr noundef %0)
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %21, label %19

19:                                               ; preds = %17
  tail call void @glad_egl_load_EGL_VERSION_1_0(ptr noundef %1, ptr noundef %2)
  tail call void @glad_egl_load_EGL_VERSION_1_1(ptr noundef %1, ptr noundef %2)
  tail call void @glad_egl_load_EGL_VERSION_1_2(ptr noundef %1, ptr noundef %2)
  tail call void @glad_egl_load_EGL_VERSION_1_4(ptr noundef %1, ptr noundef %2)
  tail call void @glad_egl_load_EGL_VERSION_1_5(ptr noundef %1, ptr noundef %2)
  %20 = tail call i32 @glad_egl_find_extensions_egl(ptr noundef %0)
  %.not28 = icmp eq i32 %20, 0
  %. = select i1 %.not28, i32 0, i32 %18
  br label %21

21:                                               ; preds = %19, %17, %3
  %.0 = phi i32 [ 0, %3 ], [ 0, %17 ], [ %., %19 ]
  ret i32 %.0
}

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @glad_egl_find_extensions_egl(ptr 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: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass