; LLVM IR from mlcommons/tiny :: benchmark/interface/Middlewares/ST/threadx/common/src/txe_event_flags_create.l_7440e1bd (create)

; 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_preempt_disable = external global i32, align 4
@_tx_event_flags_created_ptr = external global ptr, align 8
@_tx_event_flags_created_count = 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
@_tx_thread_system_state = external global i64, align 8

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

14:                                               ; preds = %3
  store i32 6, ptr %8, align 4, !tbaa !9
  br label %74

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = icmp ne i64 %17, 80
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  store i32 6, ptr %8, align 4, !tbaa !9
  br label %73

20:                                               ; preds = %15
  %21 = call i32 @__disable_interrupts()
  store i32 %21, ptr %7, align 4, !tbaa !9
  %22 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %23 = add i32 %22, 1
  store volatile i32 %23, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %24)
  %25 = load ptr, ptr @_tx_event_flags_created_ptr, align 8, !tbaa !5
  store ptr %25, ptr %10, align 8, !tbaa !5
  store i64 0, ptr %9, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %40, %20
  %27 = load i64, ptr %9, align 8, !tbaa !11
  %28 = load i64, ptr @_tx_event_flags_created_count, align 8, !tbaa !11
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %30, label %43

30:                                               ; preds = %26
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = icmp eq ptr %31, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  br label %43

35:                                               ; preds = %30
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TX_EVENT_FLAGS_GROUP_STRUCT, ptr %36, i32 0, i32 6
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  store ptr %38, ptr %10, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %35
  br label %40

40:                                               ; preds = %39
  %41 = load i64, ptr %9, align 8, !tbaa !11
  %42 = add i64 %41, 1
  store i64 %42, ptr %9, align 8, !tbaa !11
  br label %26, !llvm.loop !15

43:                                               ; preds = %34, %26
  %44 = call i32 @__disable_interrupts()
  store i32 %44, ptr %7, align 4, !tbaa !9
  %45 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %46 = add i32 %45, -1
  store volatile i32 %46, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %47)
  call void @_tx_thread_system_preempt_check()
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = icmp eq ptr %48, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %43
  store i32 6, ptr %8, align 4, !tbaa !9
  br label %72

52:                                               ; preds = %43
  %53 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !5
  store ptr %53, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = icmp eq ptr %54, @_tx_timer_thread
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  store i32 19, ptr %8, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %56, %52
  %58 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !11
  %59 = call i32 @_tx_ipsr_get()
  %60 = zext i32 %59 to i64
  %61 = or i64 %58, %60
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %63, label %71

63:                                               ; preds = %57
  %64 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !11
  %65 = call i32 @_tx_ipsr_get()
  %66 = zext i32 %65 to i64
  %67 = or i64 %64, %66
  %68 = icmp ult i64 %67, 4042322160
  br i1 %68, label %69, label %70

69:                                               ; preds = %63
  store i32 19, ptr %8, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %69, %63
  br label %71

71:                                               ; preds = %70, %57
  br label %72

72:                                               ; preds = %71, %51
  br label %73

73:                                               ; preds = %72, %19
  br label %74

74:                                               ; preds = %73, %14
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = icmp eq i32 %75, 0
  br i1 %76, label %77, label %81

77:                                               ; preds = %74
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = call i32 @_tx_event_flags_create(ptr noundef %78, ptr noundef %79)
  store i32 %80, ptr %8, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %77, %74
  %82 = load i32, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 %82
}

; 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 @__disable_interrupts() #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__restore_interrupt(i32 noundef) #2

declare void @_tx_thread_system_preempt_check() #3

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

declare i32 @_tx_event_flags_create(ptr noundef, ptr 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 48}
!14 = !{!"TX_EVENT_FLAGS_GROUP_STRUCT", !12, i64 0, !6, i64 8, !12, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !6, i64 56, !12, i64 64, !6, i64 72}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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_preempt_disable = external global i32, align 4
@_tx_event_flags_created_ptr = external local_unnamed_addr global ptr, align 8
@_tx_event_flags_created_count = external local_unnamed_addr 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
@_tx_thread_system_state = external global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_txe_event_flags_create(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ne ptr %0, null
  %.not = icmp eq i32 %2, 80
  %or.cond20 = and i1 %4, %.not
  br i1 %or.cond20, label %5, label %.thread

5:                                                ; preds = %3
  %6 = tail call i32 @__disable_interrupts()
  %7 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  %8 = add i32 %7, 1
  store volatile i32 %8, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  tail call void @__restore_interrupt(i32 noundef %6)
  %9 = load i64, ptr @_tx_event_flags_created_count, align 8, !tbaa !9
  %.023 = load ptr, ptr @_tx_event_flags_created_ptr, align 8, !tbaa !11
  %10 = icmp eq i64 %9, 0
  %11 = icmp eq ptr %.023, %0
  %or.cond24 = select i1 %10, i1 true, i1 %11
  br i1 %or.cond24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.026 = phi ptr [ %.0, %.lr.ph ], [ %.023, %5 ]
  %.01525 = phi i64 [ %13, %.lr.ph ], [ 0, %5 ]
  %12 = getelementptr inbounds i8, ptr %.026, i64 48
  %13 = add nuw i64 %.01525, 1
  %.0 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp uge i64 %13, %9
  %15 = icmp eq ptr %.0, %0
  %or.cond = select i1 %14, i1 true, i1 %15
  br i1 %or.cond, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.lcssa = phi i1 [ %11, %5 ], [ %15, %.lr.ph ]
  %16 = tail call i32 @__disable_interrupts()
  %17 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  %18 = add i32 %17, -1
  store volatile i32 %18, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  tail call void @__restore_interrupt(i32 noundef %16)
  tail call void @_tx_thread_system_preempt_check() #3
  br i1 %.lcssa, label %.thread, label %19

19:                                               ; preds = %._crit_edge
  %20 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !11
  %.not22 = icmp eq ptr %20, @_tx_timer_thread
  %21 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %22 = tail call i32 @_tx_ipsr_get()
  %23 = zext i32 %22 to i64
  %24 = or i64 %21, %23
  %.not18 = icmp eq i64 %24, 0
  br i1 %.not18, label %32, label %25

25:                                               ; preds = %19
  %26 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %27 = tail call i32 @_tx_ipsr_get()
  %28 = zext i32 %27 to i64
  %29 = or i64 %26, %28
  %30 = icmp ult i64 %29, 4042322160
  %brmerge = select i1 %30, i1 true, i1 %.not22
  %31 = select i1 %30, i1 true, i1 %.not22
  %.mux = select i1 %31, i32 19, i32 0
  br i1 %brmerge, label %.thread, label %33

32:                                               ; preds = %19
  br i1 %.not22, label %.thread, label %33

33:                                               ; preds = %25, %32
  %34 = tail call i32 @_tx_event_flags_create(ptr noundef nonnull %0, ptr noundef %1) #3
  br label %.thread

.thread:                                          ; preds = %25, %._crit_edge, %3, %33, %32
  %.2 = phi i32 [ %34, %33 ], [ 19, %32 ], [ 6, %._crit_edge ], [ 6, %3 ], [ %.mux, %25 ]
  ret i32 %.2
}

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

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

declare void @_tx_thread_system_preempt_check() local_unnamed_addr #2

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

declare i32 @_tx_event_flags_create(ptr noundef, ptr 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, !6, i64 0}
!6 = !{!"int", !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 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass