; LLVM IR from mlcommons/tiny :: benchmark/interface/Middlewares/ST/threadx/common/src (txe_event_flags_get)

; 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.TX_THREAD_STRUCT = type { i64, i64, ptr, ptr, ptr, i64, i64, i64, ptr, ptr, ptr, i32, i32, i32, i32, i32, ptr, ptr, i64, %struct.TX_TIMER_INTERNAL_STRUCT, ptr, ptr, ptr, ptr, i64, ptr, i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, ptr, ptr, ptr, i64 }
%struct.TX_TIMER_INTERNAL_STRUCT = type { i64, i64, ptr, i64, ptr, ptr, ptr }
%struct.TX_EVENT_FLAGS_GROUP_STRUCT = type { i64, ptr, i64, i32, ptr, i32, ptr, ptr, i64, ptr }

@_tx_thread_system_state = external global i64, align 8
@_tx_thread_current_ptr = external global ptr, align 8
@_tx_timer_thread = external global %struct.TX_THREAD_STRUCT, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_txe_event_flags_get(ptr noundef %0, i64 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i64 %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store i32 0, ptr %11, align 4, !tbaa !11
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %5
  store i32 6, ptr %11, align 4, !tbaa !11
  br label %46

16:                                               ; preds = %5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TX_EVENT_FLAGS_GROUP_STRUCT, ptr %17, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = icmp ne i64 %19, 1146504270
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i32 6, ptr %11, align 4, !tbaa !11
  br label %45

22:                                               ; preds = %16
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store i32 3, ptr %11, align 4, !tbaa !11
  br label %44

26:                                               ; preds = %22
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %43

29:                                               ; preds = %26
  %30 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %31 = call i32 @_tx_ipsr_get()
  %32 = zext i32 %31 to i64
  %33 = or i64 %30, %32
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %29
  store i32 4, ptr %11, align 4, !tbaa !11
  br label %42

36:                                               ; preds = %29
  %37 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !5
  store ptr %37, ptr %12, align 8, !tbaa !5
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = icmp eq ptr %38, @_tx_timer_thread
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  store i32 4, ptr %11, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %40, %36
  br label %42

42:                                               ; preds = %41, %35
  br label %43

43:                                               ; preds = %42, %26
  br label %44

44:                                               ; preds = %43, %25
  br label %45

45:                                               ; preds = %44, %21
  br label %46

46:                                               ; preds = %45, %15
  %47 = load i32, ptr %11, align 4, !tbaa !11
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %46
  %50 = load i32, ptr %8, align 4, !tbaa !11
  %51 = icmp ugt i32 %50, 3
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  store i32 8, ptr %11, align 4, !tbaa !11
  br label %53

53:                                               ; preds = %52, %49
  br label %54

54:                                               ; preds = %53, %46
  %55 = load i32, ptr %11, align 4, !tbaa !11
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %64

57:                                               ; preds = %54
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i64, ptr %7, align 8, !tbaa !9
  %60 = load i32, ptr %8, align 4, !tbaa !11
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load i64, ptr %10, align 8, !tbaa !9
  %63 = call i32 @_tx_event_flags_get(ptr noundef %58, i64 noundef %59, i32 noundef %60, ptr noundef %61, i64 noundef %62)
  store i32 %63, ptr %11, align 4, !tbaa !11
  br label %64

64:                                               ; preds = %57, %54
  %65 = load i32, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret i32 %65
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @_tx_ipsr_get() #2

declare i32 @_tx_event_flags_get(ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) #3

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

attributes #0 = { 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 = { alwaysinline 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 #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 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"TX_EVENT_FLAGS_GROUP_STRUCT", !10, i64 0, !6, i64 8, !10, i64 16, !12, i64 24, !6, i64 32, !12, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !6, i64 72}


; 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.TX_THREAD_STRUCT = type { i64, i64, ptr, ptr, ptr, i64, i64, i64, ptr, ptr, ptr, i32, i32, i32, i32, i32, ptr, ptr, i64, %struct.TX_TIMER_INTERNAL_STRUCT, ptr, ptr, ptr, ptr, i64, ptr, i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, ptr, ptr, ptr, i64 }
%struct.TX_TIMER_INTERNAL_STRUCT = type { i64, i64, ptr, i64, ptr, ptr, ptr }

@_tx_thread_system_state = external global i64, align 8
@_tx_thread_current_ptr = external local_unnamed_addr global ptr, align 8
@_tx_timer_thread = external global %struct.TX_THREAD_STRUCT, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_txe_event_flags_get(ptr noundef %0, i64 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %0, null
  br i1 %6, label %20, label %7

7:                                                ; preds = %5
  %8 = load i64, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i64 %8, 1146504270
  br i1 %.not, label %9, label %20

9:                                                ; preds = %7
  %10 = icmp eq ptr %3, null
  br i1 %10, label %20, label %11

11:                                               ; preds = %9
  %.not15 = icmp eq i64 %4, 0
  br i1 %.not15, label %20, label %12

12:                                               ; preds = %11
  %13 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !12
  %14 = tail call i32 @_tx_ipsr_get()
  %15 = zext i32 %14 to i64
  %16 = or i64 %13, %15
  %.not16 = icmp eq i64 %16, 0
  br i1 %.not16, label %17, label %20

17:                                               ; preds = %12
  %18 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !13
  %19 = icmp ne ptr %18, @_tx_timer_thread
  %spec.select17 = select i1 %19, i32 0, i32 4
  br label %20

20:                                               ; preds = %17, %12, %9, %7, %5, %11
  %21 = phi i1 [ true, %11 ], [ false, %5 ], [ false, %7 ], [ false, %9 ], [ false, %12 ], [ %19, %17 ]
  %.0 = phi i32 [ 0, %11 ], [ 6, %5 ], [ 6, %7 ], [ 3, %9 ], [ 4, %12 ], [ %spec.select17, %17 ]
  %22 = icmp ugt i32 %2, 3
  %or.cond = and i1 %22, %21
  %spec.store.select = select i1 %or.cond, i32 8, i32 %.0
  %23 = icmp eq i32 %spec.store.select, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = tail call i32 @_tx_event_flags_get(ptr noundef %0, i64 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4) #3
  br label %26

26:                                               ; preds = %24, %20
  %.1 = phi i32 [ %25, %24 ], [ %spec.store.select, %20 ]
  ret i32 %.1
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @_tx_ipsr_get() local_unnamed_addr #1

declare i32 @_tx_event_flags_get(ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 = { alwaysinline 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 #2 = { "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 }

!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 = !{!"TX_EVENT_FLAGS_GROUP_STRUCT", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !10, i64 32, !11, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !10, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!10, !10, i64 0}


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