; LLVM IR from StanfordVL/GibsonEnv :: gibson/core/channels/glad (glx_dyn)

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

@gladLoaderLoadGLX.NAMES = external hidden global [2 x ptr], align 16
@_glx_handle = external hidden global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

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

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

10:                                               ; preds = %2
  %11 = call ptr @glad_get_dlopen_handle(ptr noundef @gladLoaderLoadGLX.NAMES, i32 noundef 2)
  store ptr %11, ptr @_glx_handle, align 8, !tbaa !5
  %12 = load ptr, ptr @_glx_handle, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  %14 = zext i1 %13 to i32
  store i32 %14, ptr %6, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %10, %2
  %16 = load ptr, ptr @_glx_handle, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %37

18:                                               ; preds = %15
  %19 = load ptr, ptr @_glx_handle, align 8, !tbaa !5
  %20 = call ptr @glad_dlsym_handle(ptr noundef %19, ptr noundef @.str.3)
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %28

23:                                               ; preds = %18
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call i32 @gladLoadGLXUserPtr(ptr noundef %24, i32 noundef %25, ptr noundef @glad_glx_get_proc, ptr noundef %26)
  store i32 %27, ptr %5, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %23, %18
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %36, label %31

31:                                               ; preds = %28
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %31
  %35 = load ptr, ptr @_glx_handle, align 8, !tbaa !5
  call void @glad_close_dlopen_handle(ptr noundef %35)
  store ptr null, ptr @_glx_handle, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %34, %31, %28
  br label %37

37:                                               ; preds = %36, %15
  %38 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %38
}

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @glad_close_dlopen_handle(ptr noundef) #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 = { 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"

@gladLoaderLoadGLX.NAMES = external hidden global [2 x ptr], align 16
@_glx_handle = external hidden local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gladLoaderLoadGLX(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @_glx_handle, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %.thread

5:                                                ; preds = %2
  %6 = tail call ptr @glad_get_dlopen_handle(ptr noundef nonnull @gladLoaderLoadGLX.NAMES, i32 noundef 2)
  store ptr %6, ptr @_glx_handle, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %16, label %.thread

.thread:                                          ; preds = %2, %5
  %.0713 = phi i1 [ %7, %5 ], [ false, %2 ]
  %8 = phi ptr [ %6, %5 ], [ %3, %2 ]
  %9 = tail call ptr @glad_dlsym_handle(ptr noundef nonnull %8, ptr noundef nonnull @.str.3)
  %.not10 = icmp eq ptr %9, null
  br i1 %.not10, label %12, label %10

10:                                               ; preds = %.thread
  %11 = tail call i32 @gladLoadGLXUserPtr(ptr noundef %0, i32 noundef %1, ptr noundef nonnull @glad_glx_get_proc, ptr noundef nonnull %9)
  br label %12

12:                                               ; preds = %10, %.thread
  %.0 = phi i32 [ %11, %10 ], [ 0, %.thread ]
  %13 = icmp eq i32 %.0, 0
  %or.cond = and i1 %.0713, %13
  br i1 %or.cond, label %14, label %16

14:                                               ; preds = %12
  %15 = load ptr, ptr @_glx_handle, align 8, !tbaa !5
  tail call void @glad_close_dlopen_handle(ptr noundef %15)
  store ptr null, ptr @_glx_handle, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %12, %14, %5
  %.1 = phi i32 [ 0, %14 ], [ %.0, %12 ], [ 0, %5 ]
  ret i32 %.1
}

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @glad_close_dlopen_handle(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" }

!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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass