; LLVM IR from eProsima/Fast-DDS :: test/realtime/mutex_testing_tool (TMutex)

; 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.std::array" = type { [30 x %"struct.eprosima::fastdds::tmutex_record"] }
%"struct.eprosima::fastdds::tmutex_record" = type { i32, ptr, i32 }

@_ZN8eprosima7fastdds19g_tmutex_thread_pidE = external dso_local global { i32 }, align 4
@_ZN8eprosima7fastdds16g_tmutex_recordsE = external dso_local global %"struct.std::array", align 8
@_ZN8eprosima7fastdds20g_tmutex_records_endE = external dso_local global i32, align 4
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@__PRETTY_FUNCTION__._ZN8eprosima7fastdds20tmutex_record_mutex_ENS0_8LockTypeEP15pthread_mutex_t = external hidden unnamed_addr constant [74 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [63 x i8], align 1

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

; Function Attrs: 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 dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EEixEm(ptr noundef nonnull align 8 dereferenceable(720), i64 noundef) #0 align 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 nounwind uwtable
declare dso_local noundef i32 @_ZNKSt13__atomic_baseIiEcviEv(ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8eprosima7fastdds20tmutex_record_mutex_ENS0_8LockTypeEP15pthread_mutex_t(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %6 = call noundef i32 @_ZNKSt13__atomic_baseIiEcviEv(ptr noundef nonnull align 4 dereferenceable(4) @_ZN8eprosima7fastdds19g_tmutex_thread_pidE) #3
  %7 = icmp slt i32 0, %6
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  br label %11

9:                                                ; preds = %2
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 91, ptr noundef @__PRETTY_FUNCTION__._ZN8eprosima7fastdds20tmutex_record_mutex_ENS0_8LockTypeEP15pthread_mutex_t) #4
  unreachable

10:                                               ; No predecessors!
  br label %11

11:                                               ; preds = %10, %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !9
  %13 = call noundef i32 @_ZN8eprosima7fastdds18tmutex_find_recordEP15pthread_mutex_t(ptr noundef %12)
  store i32 %13, ptr %5, align 4, !tbaa !11
  %14 = load i32, ptr %5, align 4, !tbaa !11
  %15 = icmp sge i32 -1, %14
  br i1 %15, label %16, label %37

16:                                               ; preds = %11
  %17 = load i32, ptr @_ZN8eprosima7fastdds20g_tmutex_records_endE, align 4, !tbaa !11
  %18 = add nsw i32 %17, 1
  %19 = sext i32 %18 to i64
  %20 = icmp ugt i64 30, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  br label %24

22:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 98, ptr noundef @__PRETTY_FUNCTION__._ZN8eprosima7fastdds20tmutex_record_mutex_ENS0_8LockTypeEP15pthread_mutex_t) #4
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  %25 = load i32, ptr @_ZN8eprosima7fastdds20g_tmutex_records_endE, align 4, !tbaa !11
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @_ZN8eprosima7fastdds20g_tmutex_records_endE, align 4, !tbaa !11
  store i32 %26, ptr %5, align 4, !tbaa !11
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EEixEm(ptr noundef nonnull align 8 dereferenceable(720) @_ZN8eprosima7fastdds16g_tmutex_recordsE, i64 noundef %29) #3
  %31 = getelementptr inbounds %"struct.eprosima::fastdds::tmutex_record", ptr %30, i32 0, i32 0
  store i32 %27, ptr %31, align 8, !tbaa !13
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = load i32, ptr %5, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EEixEm(ptr noundef nonnull align 8 dereferenceable(720) @_ZN8eprosima7fastdds16g_tmutex_recordsE, i64 noundef %34) #3
  %36 = getelementptr inbounds %"struct.eprosima::fastdds::tmutex_record", ptr %35, i32 0, i32 1
  store ptr %32, ptr %36, align 8, !tbaa !15
  br label %37

37:                                               ; preds = %24, %11
  %38 = load i32, ptr %5, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EEixEm(ptr noundef nonnull align 8 dereferenceable(720) @_ZN8eprosima7fastdds16g_tmutex_recordsE, i64 noundef %39) #3
  %41 = getelementptr inbounds %"struct.eprosima::fastdds::tmutex_record", ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = add i32 %42, 1
  store i32 %43, ptr %41, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind }
attributes #4 = { noreturn 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 = !{!"_ZTSN8eprosima7fastdds8LockTypeE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN8eprosima7fastdds13tmutex_recordE", !6, i64 0, !10, i64 8, !12, i64 16}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !12, i64 16}


; 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.std::array" = type { [30 x %"struct.eprosima::fastdds::tmutex_record"] }
%"struct.eprosima::fastdds::tmutex_record" = type { i32, ptr, i32 }

@_ZN8eprosima7fastdds19g_tmutex_thread_pidE = external dso_local global { i32 }, align 4
@_ZN8eprosima7fastdds16g_tmutex_recordsE = external dso_local global %"struct.std::array", align 8
@_ZN8eprosima7fastdds20g_tmutex_records_endE = external dso_local local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [24 x i8], align 1
@__PRETTY_FUNCTION__._ZN8eprosima7fastdds20tmutex_record_mutex_ENS0_8LockTypeEP15pthread_mutex_t = external hidden unnamed_addr constant [74 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [63 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EEixEm(ptr noundef nonnull align 8 dereferenceable(720), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNKSt13__atomic_baseIiEcviEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8eprosima7fastdds20tmutex_record_mutex_ENS0_8LockTypeEP15pthread_mutex_t(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i32 @_ZNKSt13__atomic_baseIiEcviEv(ptr noundef nonnull align 4 dereferenceable(4) @_ZN8eprosima7fastdds19g_tmutex_thread_pidE) #2
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 91, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8eprosima7fastdds20tmutex_record_mutex_ENS0_8LockTypeEP15pthread_mutex_t) #3
  unreachable

6:                                                ; preds = %2
  %7 = tail call noundef i32 @_ZN8eprosima7fastdds18tmutex_find_recordEP15pthread_mutex_t(ptr noundef %1)
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %9, label %._crit_edge

._crit_edge:                                      ; preds = %6
  %.pre = zext nneg i32 %7 to i64
  br label %19

9:                                                ; preds = %6
  %10 = load i32, ptr @_ZN8eprosima7fastdds20g_tmutex_records_endE, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  %12 = icmp ult i32 %11, 30
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 98, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8eprosima7fastdds20tmutex_record_mutex_ENS0_8LockTypeEP15pthread_mutex_t) #3
  unreachable

14:                                               ; preds = %9
  %15 = zext nneg i32 %11 to i64
  store i32 %11, ptr @_ZN8eprosima7fastdds20g_tmutex_records_endE, align 4, !tbaa !5
  %16 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EEixEm(ptr noundef nonnull align 8 dereferenceable(720) @_ZN8eprosima7fastdds16g_tmutex_recordsE, i64 noundef %15) #2
  store i32 %0, ptr %16, align 8, !tbaa !9
  %17 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EEixEm(ptr noundef nonnull align 8 dereferenceable(720) @_ZN8eprosima7fastdds16g_tmutex_recordsE, i64 noundef %15) #2
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %1, ptr %18, align 8, !tbaa !13
  br label %19

19:                                               ; preds = %._crit_edge, %14
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %15, %14 ]
  %20 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EEixEm(ptr noundef nonnull align 8 dereferenceable(720) @_ZN8eprosima7fastdds16g_tmutex_recordsE, i64 noundef %.pre-phi) #2
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = load i32, ptr %21, align 8, !tbaa !14
  %23 = add i32 %22, 1
  store i32 %23, ptr %21, align 8, !tbaa !14
  ret void
}

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 = { 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 = { nounwind }
attributes #3 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN8eprosima7fastdds13tmutex_recordE", !11, i64 0, !12, i64 8, !6, i64 16}
!11 = !{!"_ZTSN8eprosima7fastdds8LockTypeE", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!10, !6, i64 16}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass