; LLVM IR from mlcommons/tiny :: benchmark/interface/Middlewares/ST/threadx/common/src (tx_semaphore_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_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
@_tx_thread_current_ptr = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_tx_semaphore_get(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 ptr, align 8
  %9 = 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 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !11
  %10 = call i32 @__disable_interrupts()
  store i32 %10, ptr %5, align 4, !tbaa !11
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %11, i32 0, i32 2
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %15, label %21

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = add i64 %18, -1
  store i64 %19, ptr %17, align 8, !tbaa !13
  %20 = load i32, ptr %5, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %20)
  br label %97

21:                                               ; preds = %2
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %94

24:                                               ; preds = %21
  %25 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  %28 = load i32, ptr %5, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %28)
  store i32 13, ptr %9, align 4, !tbaa !11
  br label %93

29:                                               ; preds = %24
  %30 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !5
  store ptr %30, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %31, i32 0, i32 20
  store ptr @_tx_semaphore_cleanup, ptr %32, align 8, !tbaa !15
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %34, i32 0, i32 21
  store ptr %33, ptr %35, align 8, !tbaa !18
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %36, i32 0, i32 39
  %38 = load i64, ptr %37, align 8, !tbaa !19
  %39 = add i64 %38, 1
  store i64 %39, ptr %37, align 8, !tbaa !19
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %40, i32 0, i32 4
  %42 = load i32, ptr %41, align 8, !tbaa !20
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %54

44:                                               ; preds = %29
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %46, i32 0, i32 3
  store ptr %45, ptr %47, align 8, !tbaa !21
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %49, i32 0, i32 22
  store ptr %48, ptr %50, align 8, !tbaa !22
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %52, i32 0, i32 23
  store ptr %51, ptr %53, align 8, !tbaa !23
  br label %73

54:                                               ; preds = %29
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !21
  store ptr %57, ptr %7, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %59, i32 0, i32 22
  store ptr %58, ptr %60, align 8, !tbaa !22
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %61, i32 0, i32 23
  %63 = load ptr, ptr %62, align 8, !tbaa !23
  store ptr %63, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %65, i32 0, i32 23
  store ptr %64, ptr %66, align 8, !tbaa !23
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %68, i32 0, i32 22
  store ptr %67, ptr %69, align 8, !tbaa !22
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %71, i32 0, i32 23
  store ptr %70, ptr %72, align 8, !tbaa !23
  br label %73

73:                                               ; preds = %54, %44
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.TX_SEMAPHORE_STRUCT, ptr %74, i32 0, i32 4
  %76 = load i32, ptr %75, align 8, !tbaa !20
  %77 = add i32 %76, 1
  store i32 %77, ptr %75, align 8, !tbaa !20
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %78, i32 0, i32 12
  store i32 6, ptr %79, align 4, !tbaa !24
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %80, i32 0, i32 14
  store i32 1, ptr %81, align 4, !tbaa !25
  %82 = load i64, ptr %4, align 8, !tbaa !9
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %83, i32 0, i32 19
  %85 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %84, i32 0, i32 0
  store i64 %82, ptr %85, align 8, !tbaa !26
  %86 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %87 = add i32 %86, 1
  store volatile i32 %87, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %88 = load i32, ptr %5, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %88)
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_tx_thread_system_suspend(ptr noundef %89)
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %90, i32 0, i32 27
  %92 = load i32, ptr %91, align 4, !tbaa !27
  store i32 %92, ptr %9, align 4, !tbaa !11
  br label %93

93:                                               ; preds = %73, %27
  br label %96

94:                                               ; preds = %21
  %95 = load i32, ptr %5, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %95)
  store i32 13, ptr %9, align 4, !tbaa !11
  br label %96

96:                                               ; preds = %94, %93
  br label %97

97:                                               ; preds = %96, %15
  %98 = load i32, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, 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 %98
}

; 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_semaphore_cleanup(ptr noundef, i64 noundef) #3

declare void @_tx_thread_system_suspend(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, !10, i64 16}
!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 = !{!16, !6, i64 192}
!16 = !{!"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, !17, 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}
!17 = !{!"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}
!18 = !{!16, !6, i64 200}
!19 = !{!16, !10, i64 320}
!20 = !{!14, !12, i64 32}
!21 = !{!14, !6, i64 24}
!22 = !{!16, !6, i64 208}
!23 = !{!16, !6, i64 216}
!24 = !{!16, !12, i64 92}
!25 = !{!16, !12, i64 100}
!26 = !{!16, !10, i64 136}
!27 = !{!16, !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
@_tx_thread_current_ptr = external local_unnamed_addr global ptr, align 8

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

6:                                                ; preds = %2
  %7 = add i64 %5, -1
  store i64 %7, ptr %4, align 8, !tbaa !5
  tail call void @__restore_interrupt(i32 noundef %3)
  br label %42

8:                                                ; preds = %2
  %.not37 = icmp eq i64 %1, 0
  br i1 %.not37, label %41, label %9

9:                                                ; preds = %8
  %10 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !12
  %.not38 = icmp eq i32 %10, 0
  br i1 %.not38, label %12, label %11

11:                                               ; preds = %9
  tail call void @__restore_interrupt(i32 noundef %3)
  br label %42

12:                                               ; preds = %9
  %13 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %13, i64 192
  store ptr @_tx_semaphore_cleanup, ptr %14, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %13, i64 200
  store ptr %0, ptr %15, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %13, i64 320
  %17 = load i64, ptr %16, align 8, !tbaa !18
  %18 = add i64 %17, 1
  store i64 %18, ptr %16, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load i32, ptr %19, align 8, !tbaa !19
  %21 = icmp eq i32 %20, 0
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  %23 = getelementptr inbounds i8, ptr %13, i64 208
  br i1 %21, label %24, label %26

24:                                               ; preds = %12
  store ptr %13, ptr %22, align 8, !tbaa !20
  store ptr %13, ptr %23, align 8, !tbaa !21
  %25 = getelementptr inbounds i8, ptr %13, i64 216
  br label %32

26:                                               ; preds = %12
  %27 = load ptr, ptr %22, align 8, !tbaa !20
  store ptr %27, ptr %23, align 8, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %27, i64 216
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %13, i64 216
  store ptr %29, ptr %30, align 8, !tbaa !22
  %31 = getelementptr inbounds i8, ptr %29, i64 208
  store ptr %13, ptr %31, align 8, !tbaa !21
  br label %32

32:                                               ; preds = %26, %24
  %.sink = phi ptr [ %28, %26 ], [ %25, %24 ]
  store ptr %13, ptr %.sink, align 8, !tbaa !22
  %33 = add i32 %20, 1
  store i32 %33, ptr %19, align 8, !tbaa !19
  %34 = getelementptr inbounds i8, ptr %13, i64 92
  store i32 6, ptr %34, align 4, !tbaa !23
  %35 = getelementptr inbounds i8, ptr %13, i64 100
  store i32 1, ptr %35, align 4, !tbaa !24
  %36 = getelementptr inbounds i8, ptr %13, i64 136
  store i64 %1, ptr %36, align 8, !tbaa !25
  %37 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !12
  %38 = add i32 %37, 1
  store volatile i32 %38, ptr @_tx_thread_preempt_disable, align 4, !tbaa !12
  tail call void @__restore_interrupt(i32 noundef %3)
  tail call void @_tx_thread_system_suspend(ptr noundef nonnull %13) #3
  %39 = getelementptr inbounds i8, ptr %13, i64 244
  %40 = load i32, ptr %39, align 4, !tbaa !26
  br label %42

41:                                               ; preds = %8
  tail call void @__restore_interrupt(i32 noundef %3)
  br label %42

42:                                               ; preds = %41, %32, %11, %6
  %.0 = phi i32 [ 0, %6 ], [ 13, %11 ], [ %40, %32 ], [ 13, %41 ]
  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_semaphore_cleanup(ptr noundef, i64 noundef) #2

declare void @_tx_thread_system_suspend(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, !7, i64 16}
!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 = !{!11, !11, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !10, i64 192}
!15 = !{!"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, !16, 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}
!16 = !{!"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}
!17 = !{!15, !10, i64 200}
!18 = !{!15, !7, i64 320}
!19 = !{!6, !11, i64 32}
!20 = !{!6, !10, i64 24}
!21 = !{!15, !10, i64 208}
!22 = !{!15, !10, i64 216}
!23 = !{!15, !11, i64 92}
!24 = !{!15, !11, i64 100}
!25 = !{!15, !7, i64 136}
!26 = !{!15, !11, i64 244}


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