; 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 }
%class.anon = type { ptr }

@_ZN8eprosima7fastdds16g_tmutex_recordsE = external dso_local global %"struct.std::array", align 8
@_ZN8eprosima7fastdds20g_tmutex_records_endE = external dso_local global i32, align 4

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN8eprosima7fastdds24tmutex_get_num_lock_typeEv() #1 {
  %1 = alloca i64, align 8
  %2 = alloca %class.anon, align 8
  %3 = alloca %class.anon, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store i64 0, ptr %1, align 8, !tbaa !5
  %4 = load i32, ptr @_ZN8eprosima7fastdds20g_tmutex_records_endE, align 4, !tbaa !9
  %5 = icmp slt i32 -1, %4
  br i1 %5, label %6, label %18

6:                                                ; preds = %0
  %7 = call noundef ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EE5beginEv(ptr noundef nonnull align 8 dereferenceable(720) @_ZN8eprosima7fastdds16g_tmutex_recordsE) #4
  %8 = call noundef ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EE5beginEv(ptr noundef nonnull align 8 dereferenceable(720) @_ZN8eprosima7fastdds16g_tmutex_recordsE) #4
  %9 = load i32, ptr @_ZN8eprosima7fastdds20g_tmutex_records_endE, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds %"struct.eprosima::fastdds::tmutex_record", ptr %8, i64 %10
  %12 = getelementptr inbounds %"struct.eprosima::fastdds::tmutex_record", ptr %11, i64 1
  %13 = getelementptr inbounds %class.anon, ptr %2, i32 0, i32 0
  store ptr %1, ptr %13, align 8, !tbaa !11
  %14 = getelementptr inbounds %class.anon, ptr %2, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8
  %16 = call ptr @"_ZSt8for_eachIPN8eprosima7fastdds13tmutex_recordEZNS1_24tmutex_get_num_lock_typeEvE3$_0ET0_T_S6_S5_"(ptr noundef %7, ptr noundef %12, ptr %15)
  %17 = getelementptr inbounds %class.anon, ptr %3, i32 0, i32 0
  store ptr %16, ptr %17, align 8
  br label %18

18:                                               ; preds = %6, %0
  %19 = load i64, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret i64 %19
}

; Function Attrs: mustprogress uwtable
declare hidden ptr @"_ZSt8for_eachIPN8eprosima7fastdds13tmutex_recordEZNS1_24tmutex_get_num_lock_typeEvE3$_0ET0_T_S6_S5_"(ptr noundef, ptr noundef, ptr) #1

; Function Attrs: mustprogress nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EE5beginEv(ptr noundef nonnull align 8 dereferenceable(720)) #2 align 2

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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.std::array" = type { [30 x %"struct.eprosima::fastdds::tmutex_record"] }
%"struct.eprosima::fastdds::tmutex_record" = type { i32, ptr, i32 }

@_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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN8eprosima7fastdds24tmutex_get_num_lock_typeEv() local_unnamed_addr #1 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  store i64 0, ptr %1, align 8, !tbaa !5
  %2 = load i32, ptr @_ZN8eprosima7fastdds20g_tmutex_records_endE, align 4, !tbaa !9
  %3 = icmp sgt i32 %2, -1
  br i1 %3, label %4, label %10

4:                                                ; preds = %0
  %5 = tail call noundef ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EE5beginEv(ptr noundef nonnull align 8 dereferenceable(720) @_ZN8eprosima7fastdds16g_tmutex_recordsE) #4
  %6 = zext nneg i32 %2 to i64
  %7 = getelementptr inbounds %"struct.eprosima::fastdds::tmutex_record", ptr %5, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  %9 = call ptr @"_ZSt8for_eachIPN8eprosima7fastdds13tmutex_recordEZNS1_24tmutex_get_num_lock_typeEvE3$_0ET0_T_S6_S5_"(ptr noundef %5, ptr noundef nonnull %8, ptr nonnull %1)
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %4, %0
  %11 = phi i64 [ %.pre, %4 ], [ 0, %0 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i64 %11
}

; Function Attrs: mustprogress uwtable
declare hidden ptr @"_ZSt8for_eachIPN8eprosima7fastdds13tmutex_recordEZNS1_24tmutex_get_num_lock_typeEvE3$_0ET0_T_S6_S5_"(ptr noundef, ptr noundef, ptr) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIN8eprosima7fastdds13tmutex_recordELm30EE5beginEv(ptr noundef nonnull align 8 dereferenceable(720)) local_unnamed_addr #2 align 2

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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