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

; 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_SEMAPHORE_STRUCT = type { i64, ptr, i64, ptr, i32, ptr, ptr, ptr }
%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

; Function Attrs: nounwind uwtable
define dso_local i32 @_tx_semaphore_ceiling_put(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, 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 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !11
  %12 = call i32 @__disable_interrupts()
  store i32 %12, ptr %5, align 4, !tbaa !11
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %13, i32 0, i32 4
  %15 = load i32, ptr %14, align 8, !tbaa !13
  store i32 %15, ptr %8, align 4, !tbaa !11
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %42

18:                                               ; preds = %2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %19, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = icmp uge i64 %21, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %18
  %25 = load i32, ptr %5, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %25)
  store i32 33, ptr %11, align 4, !tbaa !11
  br label %41

26:                                               ; preds = %18
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %27, i32 0, i32 2
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = add i64 %29, 1
  store i64 %30, ptr %28, align 8, !tbaa !15
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %31, i32 0, i32 7
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  store ptr %33, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %34)
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %40

37:                                               ; preds = %26
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  call void %38(ptr noundef %39)
  br label %40

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

41:                                               ; preds = %40, %24
  br label %90

42:                                               ; preds = %2
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  store ptr %45, ptr %7, align 8, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !11
  %47 = add i32 %46, -1
  store i32 %47, ptr %8, align 4, !tbaa !11
  %48 = load i32, ptr %8, align 4, !tbaa !11
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %42
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %51, i32 0, i32 3
  store ptr null, ptr %52, align 8, !tbaa !17
  br label %69

53:                                               ; preds = %42
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %54, i32 0, i32 22
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  store ptr %56, ptr %9, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %58, i32 0, i32 3
  store ptr %57, ptr %59, align 8, !tbaa !17
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %60, i32 0, i32 23
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  store ptr %62, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %64, i32 0, i32 23
  store ptr %63, ptr %65, align 8, !tbaa !21
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %67, i32 0, i32 22
  store ptr %66, ptr %68, align 8, !tbaa !18
  br label %69

69:                                               ; preds = %53, %50
  %70 = load i32, ptr %8, align 4, !tbaa !11
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %71, i32 0, i32 4
  store i32 %70, ptr %72, align 8, !tbaa !13
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %73, i32 0, i32 20
  store ptr null, ptr %74, align 8, !tbaa !22
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %75, i32 0, i32 27
  store i32 0, ptr %76, align 4, !tbaa !23
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %77, i32 0, i32 7
  %79 = load ptr, ptr %78, align 8, !tbaa !16
  store ptr %79, ptr %6, align 8, !tbaa !5
  %80 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %81 = add i32 %80, 1
  store volatile i32 %81, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %82 = load i32, ptr %5, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %82)
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_tx_thread_system_resume(ptr noundef %83)
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %89

86:                                               ; preds = %69
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  call void %87(ptr noundef %88)
  br label %89

89:                                               ; preds = %86, %69
  br label %90

90:                                               ; preds = %89, %41
  %91 = load i32, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, 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 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %91
}

; 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_resume(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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 32}
!14 = !{!"TX_SEMAPHORE_STRUCT", !10, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !12, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!15 = !{!14, !10, i64 16}
!16 = !{!14, !6, i64 56}
!17 = !{!14, !6, i64 24}
!18 = !{!19, !6, i64 208}
!19 = !{!"TX_THREAD_STRUCT", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !12, i64 88, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104, !6, i64 112, !6, i64 120, !10, i64 128, !20, i64 136, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !10, i64 224, !6, i64 232, !12, i64 240, !12, i64 244, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !12, i64 280, !12, i64 284, !12, i64 288, !12, i64 292, !6, i64 296, !6, i64 304, !6, i64 312, !10, i64 320}
!20 = !{!"TX_TIMER_INTERNAL_STRUCT", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!21 = !{!19, !6, i64 216}
!22 = !{!19, !6, i64 192}
!23 = !{!19, !12, i64 244}


; 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"

@_tx_thread_preempt_disable = external global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 34) i32 @_tx_semaphore_ceiling_put(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @__disable_interrupts()
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %16

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %.not37 = icmp ult i64 %9, %1
  br i1 %.not37, label %11, label %10

10:                                               ; preds = %7
  tail call void @__restore_interrupt(i32 noundef %3)
  br label %36

11:                                               ; preds = %7
  %12 = add nuw i64 %9, 1
  store i64 %12, ptr %8, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %0, i64 56
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  tail call void @__restore_interrupt(i32 noundef %3)
  %.not38 = icmp eq ptr %14, null
  br i1 %.not38, label %36, label %15

15:                                               ; preds = %11
  tail call void %14(ptr noundef nonnull %0) #3
  br label %36

16:                                               ; preds = %2
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = add i32 %5, -1
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %28, label %21

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %18, i64 208
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %18, i64 216
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %23, i64 216
  store ptr %25, ptr %26, align 8, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %25, i64 208
  store ptr %23, ptr %27, align 8, !tbaa !15
  br label %28

28:                                               ; preds = %16, %21
  %.sink = phi ptr [ %23, %21 ], [ null, %16 ]
  store ptr %.sink, ptr %17, align 8
  store i32 %19, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %18, i64 192
  store ptr null, ptr %29, align 8, !tbaa !19
  %30 = getelementptr inbounds i8, ptr %18, i64 244
  store i32 0, ptr %30, align 4, !tbaa !20
  %31 = getelementptr inbounds i8, ptr %0, i64 56
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !21
  %34 = add i32 %33, 1
  store volatile i32 %34, ptr @_tx_thread_preempt_disable, align 4, !tbaa !21
  tail call void @__restore_interrupt(i32 noundef %3)
  tail call void @_tx_thread_system_resume(ptr noundef %18) #3
  %.not = icmp eq ptr %32, null
  br i1 %.not, label %36, label %35

35:                                               ; preds = %28
  tail call void %32(ptr noundef nonnull %0) #3
  br label %36

36:                                               ; preds = %11, %15, %28, %35, %10
  %.0 = phi i32 [ 33, %10 ], [ 0, %35 ], [ 0, %28 ], [ 0, %15 ], [ 0, %11 ]
  ret i32 %.0
}

; 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_resume(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, !11, i64 32}
!6 = !{!"TX_SEMAPHORE_STRUCT", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !11, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!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 = !{!6, !7, i64 16}
!13 = !{!6, !10, i64 56}
!14 = !{!6, !10, i64 24}
!15 = !{!16, !10, i64 208}
!16 = !{!"TX_THREAD_STRUCT", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !10, i64 112, !10, i64 120, !7, i64 128, !17, i64 136, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !7, i64 224, !10, i64 232, !11, i64 240, !11, i64 244, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !11, i64 280, !11, i64 284, !11, i64 288, !11, i64 292, !10, i64 296, !10, i64 304, !10, i64 312, !7, i64 320}
!17 = !{!"TX_TIMER_INTERNAL_STRUCT", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!18 = !{!16, !10, i64 216}
!19 = !{!16, !10, i64 192}
!20 = !{!16, !11, i64 244}
!21 = !{!11, !11, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass