; LLVM IR from StanfordVL/GibsonEnv :: gibson/core/channels/glad (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"

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@glad_eglGetDisplay = external dso_local global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@glad_eglGetCurrentDisplay = external dso_local global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@glad_eglQueryString = external dso_local global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@glad_eglGetError = external dso_local global ptr, align 8

; 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 @.str, ptr noundef %11)
  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 @.str.1, ptr noundef %14)
  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 @.str.2, ptr noundef %17)
  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 @.str.3, ptr noundef %20)
  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 %65

34:                                               ; preds = %30
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i32 @find_coreEGL(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 %65

40:                                               ; preds = %34
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  call void @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 @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 @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 @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 @load_EGL_VERSION_1_5(ptr noundef %49, ptr noundef %50)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call i32 @find_extensionsEGL(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 %65

55:                                               ; preds = %40
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  call void @load_EGL_EXT_platform_base(ptr noundef %56, ptr noundef %57)
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  call void @load_EGL_EXT_device_enumeration(ptr noundef %58, ptr noundef %59)
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  call void @load_EGL_EXT_device_query(ptr noundef %60, ptr noundef %61)
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  call void @load_EGL_EXT_device_base(ptr noundef %62, ptr noundef %63)
  %64 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %64, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %65

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

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

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

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

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @load_EGL_EXT_device_base(ptr noundef, 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"

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@glad_eglGetDisplay = external dso_local local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@glad_eglGetCurrentDisplay = external dso_local local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@glad_eglQueryString = external dso_local local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@glad_eglGetError = external dso_local local_unnamed_addr global ptr, align 8

; 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 nonnull @.str, ptr noundef %2) #1
  store ptr %4, ptr @glad_eglGetDisplay, align 8, !tbaa !5
  %5 = tail call ptr %1(ptr noundef nonnull @.str.1, ptr noundef %2) #1
  store ptr %5, ptr @glad_eglGetCurrentDisplay, align 8, !tbaa !5
  %6 = tail call ptr %1(ptr noundef nonnull @.str.2, ptr noundef %2) #1
  store ptr %6, ptr @glad_eglQueryString, align 8, !tbaa !5
  %7 = tail call ptr %1(ptr noundef nonnull @.str.3, ptr noundef %2) #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
  %.not37 = icmp eq i4 %16, 0
  br i1 %.not37, label %17, label %22

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

19:                                               ; preds = %17
  tail call void @load_EGL_VERSION_1_0(ptr noundef %1, ptr noundef %2)
  tail call void @load_EGL_VERSION_1_1(ptr noundef %1, ptr noundef %2)
  tail call void @load_EGL_VERSION_1_2(ptr noundef %1, ptr noundef %2)
  tail call void @load_EGL_VERSION_1_4(ptr noundef %1, ptr noundef %2)
  tail call void @load_EGL_VERSION_1_5(ptr noundef %1, ptr noundef %2)
  %20 = tail call i32 @find_extensionsEGL(ptr noundef %0)
  %.not36 = icmp eq i32 %20, 0
  br i1 %.not36, label %22, label %21

21:                                               ; preds = %19
  tail call void @load_EGL_EXT_platform_base(ptr noundef %1, ptr noundef %2)
  tail call void @load_EGL_EXT_device_enumeration(ptr noundef %1, ptr noundef %2)
  tail call void @load_EGL_EXT_device_query(ptr noundef %1, ptr noundef %2)
  tail call void @load_EGL_EXT_device_base(ptr noundef %1, ptr noundef %2)
  br label %22

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

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

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

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

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @load_EGL_EXT_device_base(ptr noundef, 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