; LLVM IR from tensorflow/tensorflow :: tensorflow/lite/delegates/gpu/gl/android_sync.ll (ZN6tflite3gpu2gl11CreateFdGpuEv)

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

@_ZN12_GLOBAL__N_116eglCreateSyncKHRE = external hidden global ptr, align 8
@_ZN12_GLOBAL__N_126eglDupNativeFenceFDANDROIDE = external hidden global ptr, align 8
@_ZN12_GLOBAL__N_117eglDestroySyncKHRE = external hidden global ptr, align 8

; Function Attrs: mustprogress uwtable
declare hidden noundef zeroext i1 @_ZN12_GLOBAL__N_113IsGlSupportedEv() #0

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

declare ptr @eglGetDisplay(ptr noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6tflite3gpu2gl11CreateFdGpuEv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = call noundef zeroext i1 @_ZN12_GLOBAL__N_113IsGlSupportedEv()
  br i1 %6, label %7, label %43

7:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %8 = call ptr @eglGetDisplay(ptr noundef null)
  store ptr %8, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %39

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %12 = load ptr, ptr @_ZN12_GLOBAL__N_116eglCreateSyncKHRE, align 8, !tbaa !5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call noundef ptr %12(ptr noundef %13, i32 noundef 12612, ptr noundef null)
  store ptr %14, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %35

17:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %18 = load ptr, ptr @_ZN12_GLOBAL__N_126eglDupNativeFenceFDANDROIDE, align 8, !tbaa !5
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call noundef i32 %18(ptr noundef %19, ptr noundef %20)
  store i32 %21, ptr %4, align 4, !tbaa !9
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %24, label %29

24:                                               ; preds = %17
  %25 = load ptr, ptr @_ZN12_GLOBAL__N_117eglDestroySyncKHRE, align 8, !tbaa !5
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call noundef i32 %25(ptr noundef %26, ptr noundef %27)
  br label %31

29:                                               ; preds = %17
  %30 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %30, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %32

31:                                               ; preds = %24
  store i32 0, ptr %5, align 4
  br label %32

32:                                               ; preds = %31, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %33 = load i32, ptr %5, align 4
  switch i32 %33, label %36 [
    i32 0, label %34
  ]

34:                                               ; preds = %32
  br label %35

35:                                               ; preds = %34, %11
  store i32 0, ptr %5, align 4
  br label %36

36:                                               ; preds = %35, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %37 = load i32, ptr %5, align 4
  switch i32 %37, label %40 [
    i32 0, label %38
  ]

38:                                               ; preds = %36
  br label %39

39:                                               ; preds = %38, %7
  store i32 0, ptr %5, align 4
  br label %40

40:                                               ; preds = %39, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %41 = load i32, ptr %5, align 4
  switch i32 %41, label %46 [
    i32 0, label %42
    i32 1, label %44
  ]

42:                                               ; preds = %40
  br label %43

43:                                               ; preds = %42, %0
  call void @glFinish()
  store i32 -1, ptr %1, align 4
  br label %44

44:                                               ; preds = %43, %40
  %45 = load i32, ptr %1, align 4
  ret i32 %45

46:                                               ; preds = %40
  unreachable
}

declare void @glFinish() #2

attributes #0 = { mustprogress 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 = { "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 #3 = { 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++ 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"

@_ZN12_GLOBAL__N_116eglCreateSyncKHRE = external hidden local_unnamed_addr global ptr, align 8
@_ZN12_GLOBAL__N_126eglDupNativeFenceFDANDROIDE = external hidden local_unnamed_addr global ptr, align 8
@_ZN12_GLOBAL__N_117eglDestroySyncKHRE = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
declare hidden noundef zeroext i1 @_ZN12_GLOBAL__N_113IsGlSupportedEv() local_unnamed_addr #0

declare ptr @eglGetDisplay(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6tflite3gpu2gl11CreateFdGpuEv() local_unnamed_addr #0 {
  %1 = tail call noundef zeroext i1 @_ZN12_GLOBAL__N_113IsGlSupportedEv()
  br i1 %1, label %2, label %.critedge.thread24

2:                                                ; preds = %0
  %3 = tail call ptr @eglGetDisplay(ptr noundef null)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.critedge.thread24, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr @_ZN12_GLOBAL__N_116eglCreateSyncKHRE, align 8, !tbaa !5
  %6 = tail call noundef ptr %5(ptr noundef nonnull %3, i32 noundef 12612, ptr noundef null)
  %.not18 = icmp eq ptr %6, null
  br i1 %.not18, label %.critedge.thread24, label %7

7:                                                ; preds = %4
  %8 = load ptr, ptr @_ZN12_GLOBAL__N_126eglDupNativeFenceFDANDROIDE, align 8, !tbaa !5
  %9 = tail call noundef i32 %8(ptr noundef nonnull %3, ptr noundef nonnull %6)
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %11, label %.critedge

11:                                               ; preds = %7
  %12 = load ptr, ptr @_ZN12_GLOBAL__N_117eglDestroySyncKHRE, align 8, !tbaa !5
  %13 = tail call noundef i32 %12(ptr noundef nonnull %3, ptr noundef nonnull %6)
  br label %.critedge.thread24

.critedge.thread24:                               ; preds = %11, %4, %2, %0
  tail call void @glFinish()
  br label %.critedge

.critedge:                                        ; preds = %7, %.critedge.thread24
  %.5 = phi i32 [ -1, %.critedge.thread24 ], [ %9, %7 ]
  ret i32 %.5
}

declare void @glFinish() local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { "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++ TBAA"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass