; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/rml/client/rml_omp.ll/ZN5 (kmp3rml11omp_factory4openEv)

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

%"struct.__kmp::dynamic_link_descriptor" = type { ptr, ptr, ptr }
%"class.rml::factory" = type { ptr, ptr, ptr }
%"class.__kmp::rml::omp_factory" = type { %"class.rml::factory", ptr, ptr }

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@__PRETTY_FUNCTION__._ZN5__kmp3rml11omp_factory4openEv = external hidden unnamed_addr constant [60 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5__kmp3rml11omp_factory4openEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [4 x %"struct.__kmp::dynamic_link_descriptor"], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  %8 = getelementptr inbounds %"class.rml::factory", ptr %7, i32 0, i32 2
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  %11 = xor i1 %10, true
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  br label %15

13:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 51, ptr noundef @__PRETTY_FUNCTION__._ZN5__kmp3rml11omp_factory4openEv) #4
  unreachable

14:                                               ; No predecessors!
  br label %15

15:                                               ; preds = %14, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 96, ptr %4) #5
  %16 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %4, i32 0, i32 0
  store ptr @.str.2, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %4, i32 0, i32 1
  store ptr %3, ptr %17, align 8, !tbaa !13
  %18 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %4, i32 0, i32 2
  store ptr @__RML_open_factory, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %4, i64 1
  %20 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %19, i32 0, i32 0
  store ptr @.str.3, ptr %20, align 8, !tbaa !11
  %21 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %19, i32 0, i32 1
  %22 = getelementptr inbounds %"class.__kmp::rml::omp_factory", ptr %7, i32 0, i32 1
  store ptr %22, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %19, i32 0, i32 2
  store ptr @__KMP_make_rml_server, ptr %23, align 8, !tbaa !14
  %24 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %4, i64 2
  %25 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %24, i32 0, i32 0
  store ptr @.str.4, ptr %25, align 8, !tbaa !11
  %26 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %24, i32 0, i32 1
  %27 = getelementptr inbounds %"class.rml::factory", ptr %7, i32 0, i32 1
  store ptr %27, ptr %26, align 8, !tbaa !13
  %28 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %24, i32 0, i32 2
  store ptr @__RML_close_factory, ptr %28, align 8, !tbaa !14
  %29 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %4, i64 3
  %30 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %29, i32 0, i32 0
  store ptr @.str.5, ptr %30, align 8, !tbaa !11
  %31 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %29, i32 0, i32 1
  %32 = getelementptr inbounds %"class.__kmp::rml::omp_factory", ptr %7, i32 0, i32 2
  store ptr %32, ptr %31, align 8, !tbaa !13
  %33 = getelementptr inbounds %"struct.__kmp::dynamic_link_descriptor", ptr %29, i32 0, i32 2
  store ptr @__KMP_call_with_my_server_info, ptr %33, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %34 = getelementptr inbounds [4 x %"struct.__kmp::dynamic_link_descriptor"], ptr %4, i64 0, i64 0
  %35 = getelementptr inbounds %"class.rml::factory", ptr %7, i32 0, i32 2
  %36 = call noundef zeroext i1 @_ZN5__kmp12dynamic_linkEPKcPKNS_23dynamic_link_descriptorEmPPvi(ptr noundef @.str.6, ptr noundef %34, i64 noundef 4, ptr noundef %35, i32 noundef 7)
  br i1 %36, label %37, label %40

37:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = call noundef i32 %38(ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef 2)
  store i32 %39, ptr %5, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %42

40:                                               ; preds = %15
  %41 = getelementptr inbounds %"class.rml::factory", ptr %7, i32 0, i32 2
  store ptr null, ptr %41, align 8, !tbaa !9
  store i32 2, ptr %5, align 4, !tbaa !15
  br label %42

42:                                               ; preds = %40, %37
  %43 = load i32, ptr %5, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 96, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret i32 %43
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

declare extern_weak i32 @__RML_open_factory(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #3

declare extern_weak i32 @__KMP_make_rml_server(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

declare extern_weak void @__RML_close_factory(ptr noundef nonnull align 8 dereferenceable(24)) #3

declare extern_weak void @__KMP_call_with_my_server_info(ptr noundef, ptr noundef) #3

declare noundef zeroext i1 @_ZN5__kmp12dynamic_linkEPKcPKNS_23dynamic_link_descriptorEmPPvi(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) #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 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 = { noreturn 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { noreturn nounwind }
attributes #5 = { 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, !6, i64 16}
!10 = !{!"_ZTSN3rml7factoryE", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN5__kmp23dynamic_link_descriptorE", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!16, !16, i64 0}
!16 = !{!"_ZTSN3rml7factory11status_typeE", !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"

%"struct.__kmp::dynamic_link_descriptor" = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@__PRETTY_FUNCTION__._ZN5__kmp3rml11omp_factory4openEv = external hidden unnamed_addr constant [60 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5__kmp3rml11omp_factory4openEv(ptr noundef nonnull align 8 dereferenceable(40) %0) local_unnamed_addr #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca [4 x %"struct.__kmp::dynamic_link_descriptor"], align 16
  %4 = alloca i32, align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %8, label %7

7:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 51, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5__kmp3rml11omp_factory4openEv) #4
  unreachable

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %3) #5
  store ptr @.str.2, ptr %3, align 16, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %2, ptr %9, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr @__RML_open_factory, ptr %10, align 16, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr @.str.3, ptr %11, align 8, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %3, i64 32
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %13, ptr %12, align 16, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %3, i64 40
  store ptr @__KMP_make_rml_server, ptr %14, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %3, i64 48
  store ptr @.str.4, ptr %15, align 16, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %3, i64 56
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %17, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %3, i64 64
  store ptr @__RML_close_factory, ptr %18, align 16, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %3, i64 72
  store ptr @.str.5, ptr %19, align 8, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %3, i64 80
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %21, ptr %20, align 16, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %3, i64 88
  store ptr @__KMP_call_with_my_server_info, ptr %22, align 8, !tbaa !13
  %23 = call noundef zeroext i1 @_ZN5__kmp12dynamic_linkEPKcPKNS_23dynamic_link_descriptorEmPPvi(ptr noundef nonnull @.str.6, ptr noundef nonnull %3, i64 noundef 4, ptr noundef nonnull %5, i32 noundef 7)
  br i1 %23, label %24, label %27

24:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  %25 = load ptr, ptr %2, align 8, !tbaa !14
  %26 = call noundef i32 %25(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef 2)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  br label %28

27:                                               ; preds = %8
  store ptr null, ptr %5, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %27, %24
  %.0 = phi i32 [ %26, %24 ], [ 2, %27 ]
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret i32 %.0
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

declare extern_weak i32 @__RML_open_factory(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #3

declare extern_weak i32 @__KMP_make_rml_server(ptr noundef nonnull align 8 dereferenceable(40), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

declare extern_weak void @__RML_close_factory(ptr noundef nonnull align 8 dereferenceable(24)) #3

declare extern_weak void @__KMP_call_with_my_server_info(ptr noundef, ptr noundef) #3

declare noundef zeroext i1 @_ZN5__kmp12dynamic_linkEPKcPKNS_23dynamic_link_descriptorEmPPvi(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { noreturn 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { noreturn nounwind }
attributes #5 = { 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, !7, i64 16}
!6 = !{!"_ZTSN3rml7factoryE", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"_ZTSN5__kmp23dynamic_link_descriptorE", !7, i64 0, !7, i64 8, !7, i64 16}
!12 = !{!11, !7, i64 8}
!13 = !{!11, !7, i64 16}
!14 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass