; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/test/test_dynamic_link.ll (Z8TestMainv)

; 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.tbb::internal::dynamic_link_descriptor" = type { ptr, ptr }

@.str.21 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [123 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [1 x i8], align 1
@_ZL9LinkTable = external hidden constant [2 x %"struct.tbb::internal::dynamic_link_descriptor"], align 16
@_ZL12foo1_handler = external hidden global ptr, align 8
@_ZL12foo2_handler = external hidden global ptr, align 8
@.str.27 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z10dummy_foo1v() #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z10dummy_foo2v() #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3tbb8internal12dynamic_linkEPKcPKNS0_23dynamic_link_descriptorEmPPvi(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) #1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7Harness10GetAddressEPvPKc(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8TestMainv() #1 {
  %1 = call noundef ptr @_ZN7Harness11OpenLibraryEPKc(ptr noundef null)
  %2 = call noundef ptr @_ZN7Harness10GetAddressEPvPKc(ptr noundef %1, ptr noundef @.str.21)
  %3 = icmp ne ptr %2, null
  br i1 %3, label %4, label %9

4:                                                ; preds = %0
  %5 = call noundef ptr @_ZN7Harness11OpenLibraryEPKc(ptr noundef null)
  %6 = call noundef ptr @_ZN7Harness10GetAddressEPvPKc(ptr noundef %5, ptr noundef @.str.22)
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %4
  br label %10

9:                                                ; preds = %4, %0
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.23, i32 noundef 64, ptr noundef @.str.24, ptr noundef @.str.25)
  br label %10

10:                                               ; preds = %9, %8
  %11 = call noundef zeroext i1 @_ZN3tbb8internal12dynamic_linkEPKcPKNS0_23dynamic_link_descriptorEmPPvi(ptr noundef @.str.26, ptr noundef @_ZL9LinkTable, i64 noundef 2, ptr noundef null, i32 noundef 7)
  br i1 %11, label %12, label %31

12:                                               ; preds = %10
  %13 = load ptr, ptr @_ZL12foo1_handler, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %19

15:                                               ; preds = %12
  %16 = load ptr, ptr @_ZL12foo2_handler, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  br label %20

19:                                               ; preds = %15, %12
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.23, i32 noundef 72, ptr noundef @.str.27, ptr noundef @.str.28)
  br label %20

20:                                               ; preds = %19, %18
  %21 = load ptr, ptr @_ZL12foo1_handler, align 8, !tbaa !5
  %22 = call noundef i32 %21()
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %29

24:                                               ; preds = %20
  %25 = load ptr, ptr @_ZL12foo2_handler, align 8, !tbaa !5
  %26 = call noundef i32 %25()
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  br label %30

29:                                               ; preds = %24, %20
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.23, i32 noundef 74, ptr noundef @.str.29, ptr noundef @.str.30)
  br label %30

30:                                               ; preds = %29, %28
  br label %40

31:                                               ; preds = %10
  %32 = load ptr, ptr @_ZL12foo1_handler, align 8, !tbaa !5
  %33 = icmp eq ptr %32, @_Z10dummy_foo1v
  br i1 %33, label %34, label %38

34:                                               ; preds = %31
  %35 = load ptr, ptr @_ZL12foo2_handler, align 8, !tbaa !5
  %36 = icmp eq ptr %35, @_Z10dummy_foo2v
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  br label %39

38:                                               ; preds = %34, %31
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.23, i32 noundef 76, ptr noundef @.str.31, ptr noundef @.str.28)
  br label %39

39:                                               ; preds = %38, %37
  br label %40

40:                                               ; preds = %39, %30
  ret i32 0
}

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

!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"}


; 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.tbb::internal::dynamic_link_descriptor" = type { ptr, ptr }

@.str.21 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [123 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [1 x i8], align 1
@_ZL9LinkTable = external hidden constant [2 x %"struct.tbb::internal::dynamic_link_descriptor"], align 16
@_ZL12foo1_handler = external hidden local_unnamed_addr global ptr, align 8
@_ZL12foo2_handler = external hidden local_unnamed_addr global ptr, align 8
@.str.27 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z10dummy_foo1v() #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z10dummy_foo2v() #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3tbb8internal12dynamic_linkEPKcPKNS0_23dynamic_link_descriptorEmPPvi(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7Harness10GetAddressEPvPKc(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8TestMainv() local_unnamed_addr #1 {
  %1 = tail call noundef ptr @_ZN7Harness11OpenLibraryEPKc(ptr noundef null)
  %2 = tail call noundef ptr @_ZN7Harness10GetAddressEPvPKc(ptr noundef %1, ptr noundef nonnull @.str.21)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %6, label %3

3:                                                ; preds = %0
  %4 = tail call noundef ptr @_ZN7Harness11OpenLibraryEPKc(ptr noundef null)
  %5 = tail call noundef ptr @_ZN7Harness10GetAddressEPvPKc(ptr noundef %4, ptr noundef nonnull @.str.22)
  %.not4 = icmp eq ptr %5, null
  br i1 %.not4, label %6, label %7

6:                                                ; preds = %3, %0
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.23, i32 noundef 64, ptr noundef nonnull @.str.24, ptr noundef nonnull @.str.25)
  br label %7

7:                                                ; preds = %3, %6
  %8 = tail call noundef zeroext i1 @_ZN3tbb8internal12dynamic_linkEPKcPKNS0_23dynamic_link_descriptorEmPPvi(ptr noundef nonnull @.str.26, ptr noundef nonnull @_ZL9LinkTable, i64 noundef 2, ptr noundef null, i32 noundef 7)
  %9 = load ptr, ptr @_ZL12foo1_handler, align 8, !tbaa !5
  %10 = load ptr, ptr @_ZL12foo2_handler, align 8
  br i1 %8, label %11, label %24

11:                                               ; preds = %7
  %12 = icmp ne ptr %9, null
  %13 = icmp ne ptr %10, null
  %or.cond = select i1 %12, i1 %13, i1 false
  br i1 %or.cond, label %15, label %14

14:                                               ; preds = %11
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.23, i32 noundef 72, ptr noundef nonnull @.str.27, ptr noundef nonnull @.str.28)
  %.pre = load ptr, ptr @_ZL12foo1_handler, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %11, %14
  %16 = phi ptr [ %9, %11 ], [ %.pre, %14 ]
  %17 = tail call noundef i32 %16()
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %23

19:                                               ; preds = %15
  %20 = load ptr, ptr @_ZL12foo2_handler, align 8, !tbaa !5
  %21 = tail call noundef i32 %20()
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %28, label %23

23:                                               ; preds = %19, %15
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.23, i32 noundef 74, ptr noundef nonnull @.str.29, ptr noundef nonnull @.str.30)
  br label %28

24:                                               ; preds = %7
  %25 = icmp eq ptr %9, @_Z10dummy_foo1v
  %26 = icmp eq ptr %10, @_Z10dummy_foo2v
  %or.cond3 = select i1 %25, i1 %26, i1 false
  br i1 %or.cond3, label %28, label %27

27:                                               ; preds = %24
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.23, i32 noundef 76, ptr noundef nonnull @.str.31, ptr noundef nonnull @.str.28)
  br label %28

28:                                               ; preds = %27, %24, %23, %19
  ret i32 0
}

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

!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: GVNPass,GlobalOptPass,InstCombinePass,SimplifyCFGPass,TailCallElimPass