; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/rml/client (omp_dynamic_link)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5__kmp14dynamic_unlinkEPv(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN5__kmp12dynamic_loadEPKcPKNS_23dynamic_link_descriptorEm(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca [4097 x i8], align 16
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @_ZN3tbb8internal23suppress_unused_warningIPKcPKN5__kmp23dynamic_link_descriptorEmEEvRKT_RKT0_RKT1_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 4097, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4097, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds [4097 x i8], ptr %9, i64 0, i64 0
  %15 = call noundef i64 @_ZN5__kmpL8abs_pathEPKcPcm(ptr noundef %13, ptr noundef %14, i64 noundef 4097)
  store i64 %15, ptr %10, align 8, !tbaa !9
  %16 = load i64, ptr %10, align 8, !tbaa !9
  %17 = icmp ult i64 0, %16
  br i1 %17, label %18, label %39

18:                                               ; preds = %3
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = icmp ule i64 %19, 4097
  br i1 %20, label %21, label %39

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %22 = getelementptr inbounds [4097 x i8], ptr %9, i64 0, i64 0
  %23 = call ptr @dlopen(ptr noundef %22, i32 noundef 1) #4
  store ptr %23, ptr %11, align 8, !tbaa !5
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %34

26:                                               ; preds = %21
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = call noundef zeroext i1 @_ZN5__kmpL15resolve_symbolsEPvPKNS_23dynamic_link_descriptorEm(ptr noundef %27, ptr noundef %28, i64 noundef %29)
  br i1 %30, label %33, label %31

31:                                               ; preds = %26
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  call void @_ZN5__kmp14dynamic_unlinkEPv(ptr noundef %32)
  store ptr null, ptr %11, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %31, %26
  br label %37

34:                                               ; preds = %21
  %35 = getelementptr inbounds [4097 x i8], ptr %9, i64 0, i64 0
  %36 = call ptr @dlerror() #4
  call void (i32, ...) @_ZN5__kmpL20dynamic_link_warningENS_20dynamic_link_error_tEz(i32 noundef 1, ptr noundef %35, ptr noundef %36)
  br label %37

37:                                               ; preds = %34, %33
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %38, ptr %4, align 8
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %45

39:                                               ; preds = %18, %3
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = icmp ugt i64 %40, 4097
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  call void (i32, ...) @_ZN5__kmpL20dynamic_link_warningENS_20dynamic_link_error_tEz(i32 noundef 4)
  br label %43

43:                                               ; preds = %42, %39
  br label %44

44:                                               ; preds = %43
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %45

45:                                               ; preds = %44, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4097, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %46 = load ptr, ptr %4, align 8
  ret ptr %46
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb8internal23suppress_unused_warningIPKcPKN5__kmp23dynamic_link_descriptorEmEEvRKT_RKT0_RKT1_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #0

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

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

; Function Attrs: nounwind
declare ptr @dlopen(ptr noundef, i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN5__kmpL15resolve_symbolsEPvPKNS_23dynamic_link_descriptorEm(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN5__kmpL20dynamic_link_warningENS_20dynamic_link_error_tEz(i32 noundef, ...) #0

; Function Attrs: nounwind
declare ptr @dlerror() #3

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

attributes #0 = { mustprogress 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind "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 #4 = { 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 = !{!"long", !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"

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN5__kmp12dynamic_loadEPKcPKNS_23dynamic_link_descriptorEm(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca [4097 x i8], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @_ZN3tbb8internal23suppress_unused_warningIPKcPKN5__kmp23dynamic_link_descriptorEmEEvRKT_RKT0_RKT1_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  call void @llvm.lifetime.start.p0(i64 4097, ptr nonnull %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call noundef i64 @_ZN5__kmpL8abs_pathEPKcPcm(ptr noundef %8, ptr noundef nonnull %7, i64 noundef 4097)
  %10 = add i64 %9, -1
  %or.cond = icmp ult i64 %10, 4097
  br i1 %or.cond, label %11, label %20

11:                                               ; preds = %3
  %12 = call ptr @dlopen(ptr noundef nonnull %7, i32 noundef 1) #3
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %18, label %13

13:                                               ; preds = %11
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = call noundef zeroext i1 @_ZN5__kmpL15resolve_symbolsEPvPKNS_23dynamic_link_descriptorEm(ptr noundef nonnull %12, ptr noundef %14, i64 noundef %15)
  br i1 %16, label %23, label %17

17:                                               ; preds = %13
  call void @_ZN5__kmp14dynamic_unlinkEPv(ptr noundef nonnull %12)
  br label %23

18:                                               ; preds = %11
  %19 = call ptr @dlerror() #3
  call void (i32, ...) @_ZN5__kmpL20dynamic_link_warningENS_20dynamic_link_error_tEz(i32 noundef 1, ptr noundef nonnull %7, ptr noundef %19)
  br label %23

20:                                               ; preds = %3
  %21 = icmp ugt i64 %9, 4097
  br i1 %21, label %22, label %23

22:                                               ; preds = %20
  call void (i32, ...) @_ZN5__kmpL20dynamic_link_warningENS_20dynamic_link_error_tEz(i32 noundef 4)
  br label %23

23:                                               ; preds = %22, %20, %18, %17, %13
  %.08 = phi ptr [ %12, %13 ], [ null, %17 ], [ null, %18 ], [ null, %20 ], [ null, %22 ]
  call void @llvm.lifetime.end.p0(i64 4097, ptr nonnull %7) #3
  ret ptr %.08
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3tbb8internal23suppress_unused_warningIPKcPKN5__kmp23dynamic_link_descriptorEmEEvRKT_RKT0_RKT1_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

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

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

; Function Attrs: nounwind
declare ptr @dlopen(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN5__kmpL15resolve_symbolsEPvPKNS_23dynamic_link_descriptorEm(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN5__kmpL20dynamic_link_warningENS_20dynamic_link_error_tEz(i32 noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind
declare ptr @dlerror() local_unnamed_addr #2

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind "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 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass