; LLVM IR from ElsevierSoftwareX/SOFTX-D-20-00016 :: GameplayFootball/src/libs/glee/GLee.ll_ (GLeeLink_GLX_NV_video_output)

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

@GLeeFuncPtr_glXGetVideoDeviceNV = external dso_local global ptr, align 8
@GLeeFuncPtr_glXReleaseVideoDeviceNV = external dso_local global ptr, align 8
@GLeeFuncPtr_glXBindVideoImageNV = external dso_local global ptr, align 8
@GLeeFuncPtr_glXReleaseVideoImageNV = external dso_local global ptr, align 8
@GLeeFuncPtr_glXSendPbufferToVideoNV = external dso_local global ptr, align 8
@GLeeFuncPtr_glXGetVideoInfoNV = external dso_local global ptr, align 8
@.str.22 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @__GLeeGetProcAddress(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 @__GLeeLink_GLX_NV_video_output() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  %4 = call ptr @__GLeeGetProcAddress(ptr noundef @.str.22)
  store ptr %4, ptr @GLeeFuncPtr_glXGetVideoDeviceNV, align 8, !tbaa !9
  %5 = icmp ne ptr %4, null
  br i1 %5, label %6, label %9

6:                                                ; preds = %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %6, %0
  %10 = call ptr @__GLeeGetProcAddress(ptr noundef @.str.23)
  store ptr %10, ptr @GLeeFuncPtr_glXReleaseVideoDeviceNV, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %2, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %12, %9
  %16 = call ptr @__GLeeGetProcAddress(ptr noundef @.str.24)
  store ptr %16, ptr @GLeeFuncPtr_glXBindVideoImageNV, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %18, %15
  %22 = call ptr @__GLeeGetProcAddress(ptr noundef @.str.25)
  store ptr %22, ptr @GLeeFuncPtr_glXReleaseVideoImageNV, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %24, %21
  %28 = call ptr @__GLeeGetProcAddress(ptr noundef @.str.26)
  store ptr %28, ptr @GLeeFuncPtr_glXSendPbufferToVideoNV, align 8, !tbaa !9
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %30, %27
  %34 = call ptr @__GLeeGetProcAddress(ptr noundef @.str.27)
  store ptr %34, ptr @GLeeFuncPtr_glXGetVideoInfoNV, align 8, !tbaa !9
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %36, %33
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = icmp eq i32 %40, 6
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  store i32 2, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %48

43:                                               ; preds = %39
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %48

47:                                               ; preds = %43
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %48

48:                                               ; preds = %47, %46, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  %49 = load i32, ptr %1, align 4
  ret i32 %49
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@GLeeFuncPtr_glXGetVideoDeviceNV = external dso_local local_unnamed_addr global ptr, align 8
@GLeeFuncPtr_glXReleaseVideoDeviceNV = external dso_local local_unnamed_addr global ptr, align 8
@GLeeFuncPtr_glXBindVideoImageNV = external dso_local local_unnamed_addr global ptr, align 8
@GLeeFuncPtr_glXReleaseVideoImageNV = external dso_local local_unnamed_addr global ptr, align 8
@GLeeFuncPtr_glXSendPbufferToVideoNV = external dso_local local_unnamed_addr global ptr, align 8
@GLeeFuncPtr_glXGetVideoInfoNV = external dso_local local_unnamed_addr global ptr, align 8
@.str.22 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [18 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @__GLeeLink_GLX_NV_video_output() local_unnamed_addr #0 {
  %1 = tail call ptr @__GLeeGetProcAddress(ptr noundef nonnull @.str.22)
  store ptr %1, ptr @GLeeFuncPtr_glXGetVideoDeviceNV, align 8, !tbaa !5
  %.not = icmp ne ptr %1, null
  %spec.select = zext i1 %.not to i32
  %2 = tail call ptr @__GLeeGetProcAddress(ptr noundef nonnull @.str.23)
  store ptr %2, ptr @GLeeFuncPtr_glXReleaseVideoDeviceNV, align 8, !tbaa !5
  %.not10 = icmp eq ptr %2, null
  %3 = select i1 %.not, i32 2, i32 1
  %.1 = select i1 %.not10, i32 %spec.select, i32 %3
  %4 = tail call ptr @__GLeeGetProcAddress(ptr noundef nonnull @.str.24)
  store ptr %4, ptr @GLeeFuncPtr_glXBindVideoImageNV, align 8, !tbaa !5
  %5 = tail call ptr @__GLeeGetProcAddress(ptr noundef nonnull @.str.25)
  store ptr %5, ptr @GLeeFuncPtr_glXReleaseVideoImageNV, align 8, !tbaa !5
  %6 = tail call ptr @__GLeeGetProcAddress(ptr noundef nonnull @.str.26)
  store ptr %6, ptr @GLeeFuncPtr_glXSendPbufferToVideoNV, align 8, !tbaa !5
  %7 = tail call ptr @__GLeeGetProcAddress(ptr noundef nonnull @.str.27)
  store ptr %7, ptr @GLeeFuncPtr_glXGetVideoInfoNV, align 8, !tbaa !5
  %8 = insertelement <4 x ptr> poison, ptr %4, i64 0
  %9 = insertelement <4 x ptr> %8, ptr %5, i64 1
  %10 = insertelement <4 x ptr> %9, ptr %6, i64 2
  %11 = insertelement <4 x ptr> %10, ptr %7, i64 3
  %12 = icmp ne <4 x ptr> %11, zeroinitializer
  %13 = bitcast <4 x i1> %12 to i4
  %14 = tail call range(i4 0, 5) i4 @llvm.ctpop.i4(i4 %13)
  %15 = zext nneg i4 %14 to i32
  %op.rdx = add nuw nsw i32 %.1, %15
  %switch.selectcmp = icmp ne i32 %op.rdx, 0
  %switch.select = zext i1 %switch.selectcmp to i32
  %switch.selectcmp15 = icmp eq i32 %op.rdx, 6
  %switch.select16 = select i1 %switch.selectcmp15, i32 2, i32 %switch.select
  ret i32 %switch.select16
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i4 @llvm.ctpop.i4(i4) #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 speculatable willreturn memory(none) }

!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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass