; LLVM IR from ros2/rcutils :: src (shared_library)

; 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.rcutils_allocator_s = type { ptr, ptr, ptr, ptr, ptr }
%struct.rcutils_shared_library_s = type { ptr, ptr, %struct.rcutils_allocator_s }

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [54 x i8], align 1
@stderr = external global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) #1

declare zeroext i1 @rcutils_allocator_is_valid(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 i32 @rcutils_snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #1

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

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rcutils_unload_shared_library(ptr noundef %0) #4 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [1024 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca %struct.rcutils_allocator_s, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp eq ptr null, %10
  br i1 %11, label %12, label %15

12:                                               ; preds = %9
  br label %13

13:                                               ; preds = %12
  call void @rcutils_set_error_state(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 255)
  br label %14

14:                                               ; preds = %13
  store i32 11, ptr %2, align 4
  br label %88

15:                                               ; preds = %9
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = icmp eq ptr null, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %17
  br label %23

23:                                               ; preds = %22
  call void @rcutils_set_error_state(ptr noundef @.str.11, ptr noundef @.str.1, i64 noundef 256)
  br label %24

24:                                               ; preds = %23
  store i32 11, ptr %2, align 4
  br label %88

25:                                               ; preds = %17
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = icmp eq ptr null, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %27
  br label %33

33:                                               ; preds = %32
  call void @rcutils_set_error_state(ptr noundef @.str.12, ptr noundef @.str.1, i64 noundef 257)
  br label %34

34:                                               ; preds = %33
  store i32 11, ptr %2, align 4
  br label %88

35:                                               ; preds = %27
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %37, i32 0, i32 2
  %39 = call zeroext i1 @rcutils_allocator_is_valid(ptr noundef %38)
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 11, ptr %2, align 4
  br label %88

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = call i32 @dlclose(ptr noundef %44) #5
  store i32 %45, ptr %5, align 4, !tbaa !13
  %46 = load i32, ptr %5, align 4, !tbaa !13
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %69

48:                                               ; preds = %41
  br label %49

49:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 1024, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %50 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %51 = call ptr @dlerror() #5
  %52 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef %50, i64 noundef 1024, ptr noundef @.str.13, ptr noundef %51)
  store i32 %52, ptr %7, align 4, !tbaa !13
  %53 = load i32, ptr %7, align 4, !tbaa !13
  %54 = icmp slt i32 %53, 0
  br i1 %54, label %55, label %61

55:                                               ; preds = %49
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr @stderr, align 8, !tbaa !5
  %58 = call i64 @fwrite(ptr noundef @.str.5, i64 noundef 1, i64 noundef 53, ptr noundef %57)
  br label %59

59:                                               ; preds = %56
  br label %60

60:                                               ; preds = %59
  br label %66

61:                                               ; preds = %49
  br label %62

62:                                               ; preds = %61
  %63 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  call void @rcutils_set_error_state(ptr noundef %63, ptr noundef @.str.1, i64 noundef 265)
  br label %64

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 1024, ptr %6) #5
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  store i32 2, ptr %4, align 4, !tbaa !13
  br label %69

69:                                               ; preds = %68, %41
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %70, i32 0, i32 2
  %72 = getelementptr inbounds %struct.rcutils_allocator_s, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !12
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %77, i32 0, i32 2
  %79 = getelementptr inbounds %struct.rcutils_allocator_s, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !16
  call void %73(ptr noundef %76, ptr noundef %80)
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %81, i32 0, i32 1
  store ptr null, ptr %82, align 8, !tbaa !12
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %83, i32 0, i32 0
  store ptr null, ptr %84, align 8, !tbaa !9
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.rcutils_shared_library_s, ptr %85, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 40, ptr %8) #5
  call void @rcutils_get_zero_initialized_allocator(ptr dead_on_unwind writable sret(%struct.rcutils_allocator_s) align 8 %8)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %86, ptr align 8 %8, i64 40, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 40, ptr %8) #5
  %87 = load i32, ptr %4, align 4, !tbaa !13
  store i32 %87, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %88

88:                                               ; preds = %69, %40, %34, %24, %14
  %89 = load i32, ptr %2, align 4
  ret i32 %89
}

declare void @rcutils_get_zero_initialized_allocator(ptr dead_on_unwind writable sret(%struct.rcutils_allocator_s) align 8) #1

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }
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 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 #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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"rcutils_shared_library_s", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"rcutils_allocator_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !6, i64 48}
!17 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !5, i64 32, i64 8, !5}


; 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.rcutils_allocator_s = type { ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [54 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare zeroext i1 @rcutils_allocator_is_valid(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 i32 @rcutils_snprintf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind
declare i32 @dlclose(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 12) i32 @rcutils_unload_shared_library(ptr noundef %0) local_unnamed_addr #5 {
  %2 = alloca [1024 x i8], align 16
  %3 = alloca %struct.rcutils_allocator_s, align 8
  %4 = icmp eq ptr %0, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %1
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 255) #7
  br label %36

6:                                                ; preds = %1
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %6
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.1, i64 noundef 256) #7
  br label %36

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  tail call void @rcutils_set_error_state(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.1, i64 noundef 257) #7
  br label %36

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = tail call zeroext i1 @rcutils_allocator_is_valid(ptr noundef nonnull %16) #7
  br i1 %17, label %18, label %36

18:                                               ; preds = %15
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = tail call i32 @dlclose(ptr noundef %19) #7
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %30, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %2) #7
  %22 = tail call ptr @dlerror() #7
  %23 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef nonnull %2, i64 noundef 1024, ptr noundef nonnull @.str.13, ptr noundef %22) #7
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load ptr, ptr @stderr, align 8, !tbaa !12
  %27 = call i64 @fwrite(ptr noundef nonnull @.str.5, i64 noundef 1, i64 noundef 53, ptr noundef %26) #8
  br label %29

28:                                               ; preds = %21
  call void @rcutils_set_error_state(ptr noundef nonnull %2, ptr noundef nonnull @.str.1, i64 noundef 265) #7
  br label %29

29:                                               ; preds = %28, %25
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %2) #7
  br label %30

30:                                               ; preds = %29, %18
  %.014 = phi i32 [ 2, %29 ], [ 0, %18 ]
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %11, align 8, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %0, i64 48
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  call void %32(ptr noundef %33, ptr noundef %35) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #7
  call void @rcutils_get_zero_initialized_allocator(ptr dead_on_unwind nonnull writable sret(%struct.rcutils_allocator_s) align 8 %3) #7
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %16, ptr noundef nonnull align 8 dereferenceable(40) %3, i64 40, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #7
  br label %36

36:                                               ; preds = %15, %30, %14, %9, %5
  %.0 = phi i32 [ 11, %5 ], [ 11, %9 ], [ 11, %14 ], [ %.014, %30 ], [ 11, %15 ]
  ret i32 %.0
}

declare void @rcutils_get_zero_initialized_allocator(ptr dead_on_unwind writable sret(%struct.rcutils_allocator_s) align 8) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { mustprogress 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 = { nofree 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 #5 = { 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 #6 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind }
attributes #8 = { cold }

!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 0}
!6 = !{!"rcutils_shared_library_s", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"rcutils_allocator_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!11 = !{!6, !7, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 24}
!14 = !{!6, !7, i64 48}
!15 = !{i64 0, i64 8, !12, i64 8, i64 8, !12, i64 16, i64 8, !12, i64 24, i64 8, !12, i64 32, i64 8, !12}


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