; LLVM IR from mlcommons/tiny :: benchmark/interface/Middlewares/ST/threadx/common/src (txe_timer_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_TIMER_STRUCT = type { i64, ptr, %struct.TX_TIMER_INTERNAL_STRUCT, ptr, ptr }

@_tx_thread_preempt_disable = external global i32, align 4
@_tx_timer_created_ptr = external global ptr, align 8
@_tx_timer_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_timer_create(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, i32 noundef %6, i32 noundef %7) #0 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i64 %3, ptr %12, align 8, !tbaa !9
  store i64 %4, ptr %13, align 8, !tbaa !9
  store i64 %5, ptr %14, align 8, !tbaa !9
  store i32 %6, ptr %15, align 4, !tbaa !11
  store i32 %7, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  store i32 0, ptr %18, align 4, !tbaa !11
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %8
  store i32 21, ptr %18, align 4, !tbaa !11
  br label %78

25:                                               ; preds = %8
  %26 = load i32, ptr %16, align 4, !tbaa !11
  %27 = zext i32 %26 to i64
  %28 = icmp ne i64 %27, 88
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  store i32 21, ptr %18, align 4, !tbaa !11
  br label %77

30:                                               ; preds = %25
  %31 = call i32 @__disable_interrupts()
  store i32 %31, ptr %17, align 4, !tbaa !11
  %32 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %33 = add i32 %32, 1
  store volatile i32 %33, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %34 = load i32, ptr %17, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %34)
  %35 = load ptr, ptr @_tx_timer_created_ptr, align 8, !tbaa !5
  store ptr %35, ptr %20, align 8, !tbaa !5
  store i64 0, ptr %19, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %50, %30
  %37 = load i64, ptr %19, align 8, !tbaa !9
  %38 = load i64, ptr @_tx_timer_created_count, align 8, !tbaa !9
  %39 = icmp ult i64 %37, %38
  br i1 %39, label %40, label %53

40:                                               ; preds = %36
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %20, align 8, !tbaa !5
  %43 = icmp eq ptr %41, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %40
  br label %53

45:                                               ; preds = %40
  %46 = load ptr, ptr %20, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TX_TIMER_STRUCT, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  store ptr %48, ptr %20, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %45
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %19, align 8, !tbaa !9
  %52 = add i64 %51, 1
  store i64 %52, ptr %19, align 8, !tbaa !9
  br label %36, !llvm.loop !16

53:                                               ; preds = %44, %36
  %54 = call i32 @__disable_interrupts()
  store i32 %54, ptr %17, align 4, !tbaa !11
  %55 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %56 = add i32 %55, -1
  store volatile i32 %56, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %57 = load i32, ptr %17, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %57)
  call void @_tx_thread_system_preempt_check()
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load ptr, ptr %20, align 8, !tbaa !5
  %60 = icmp eq ptr %58, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %53
  store i32 21, ptr %18, align 4, !tbaa !11
  br label %76

62:                                               ; preds = %53
  %63 = load i64, ptr %13, align 8, !tbaa !9
  %64 = icmp eq i64 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %62
  store i32 22, ptr %18, align 4, !tbaa !11
  br label %75

66:                                               ; preds = %62
  %67 = load i32, ptr %15, align 4, !tbaa !11
  %68 = icmp ne i32 %67, 1
  br i1 %68, label %69, label %74

69:                                               ; preds = %66
  %70 = load i32, ptr %15, align 4, !tbaa !11
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %73

72:                                               ; preds = %69
  store i32 23, ptr %18, align 4, !tbaa !11
  br label %73

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

74:                                               ; preds = %73, %66
  br label %75

75:                                               ; preds = %74, %65
  br label %76

76:                                               ; preds = %75, %61
  br label %77

77:                                               ; preds = %76, %29
  br label %78

78:                                               ; preds = %77, %24
  %79 = load i32, ptr %18, align 4, !tbaa !11
  %80 = icmp eq i32 %79, 0
  br i1 %80, label %81, label %101

81:                                               ; preds = %78
  %82 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !5
  store ptr %82, ptr %21, align 8, !tbaa !5
  %83 = load ptr, ptr %21, align 8, !tbaa !5
  %84 = icmp eq ptr %83, @_tx_timer_thread
  br i1 %84, label %85, label %86

85:                                               ; preds = %81
  store i32 19, ptr %18, align 4, !tbaa !11
  br label %86

86:                                               ; preds = %85, %81
  %87 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %88 = call i32 @_tx_ipsr_get()
  %89 = zext i32 %88 to i64
  %90 = or i64 %87, %89
  %91 = icmp ne i64 %90, 0
  br i1 %91, label %92, label %100

92:                                               ; preds = %86
  %93 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %94 = call i32 @_tx_ipsr_get()
  %95 = zext i32 %94 to i64
  %96 = or i64 %93, %95
  %97 = icmp ult i64 %96, 4042322160
  br i1 %97, label %98, label %99

98:                                               ; preds = %92
  store i32 19, ptr %18, align 4, !tbaa !11
  br label %99

99:                                               ; preds = %98, %92
  br label %100

100:                                              ; preds = %99, %86
  br label %101

101:                                              ; preds = %100, %78
  %102 = load i32, ptr %18, align 4, !tbaa !11
  %103 = icmp eq i32 %102, 0
  br i1 %103, label %104, label %113

104:                                              ; preds = %101
  %105 = load ptr, ptr %9, align 8, !tbaa !5
  %106 = load ptr, ptr %10, align 8, !tbaa !5
  %107 = load ptr, ptr %11, align 8, !tbaa !5
  %108 = load i64, ptr %12, align 8, !tbaa !9
  %109 = load i64, ptr %13, align 8, !tbaa !9
  %110 = load i64, ptr %14, align 8, !tbaa !9
  %111 = load i32, ptr %15, align 4, !tbaa !11
  %112 = call i32 @_tx_timer_create(ptr noundef %105, ptr noundef %106, ptr noundef %107, i64 noundef %108, i64 noundef %109, i64 noundef %110, i32 noundef %111)
  store i32 %112, ptr %18, align 4, !tbaa !11
  br label %113

113:                                              ; preds = %104, %101
  %114 = load i32, ptr %18, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  ret i32 %114
}

; 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_timer_create(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, i32 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, !6, i64 72}
!14 = !{!"TX_TIMER_STRUCT", !10, i64 0, !6, i64 8, !15, i64 16, !6, i64 72, !6, i64 80}
!15 = !{!"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}
!16 = distinct !{!16, !17}
!17 = !{!"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_timer_created_ptr = external local_unnamed_addr global ptr, align 8
@_tx_timer_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_timer_create(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, i32 noundef %6, i32 noundef %7) local_unnamed_addr #0 {
  %9 = icmp ne ptr %0, null
  %.not = icmp eq i32 %7, 88
  %or.cond33 = and i1 %9, %.not
  br i1 %or.cond33, label %10, label %.thread36

10:                                               ; preds = %8
  %11 = tail call i32 @__disable_interrupts()
  %12 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  %13 = add i32 %12, 1
  store volatile i32 %13, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  tail call void @__restore_interrupt(i32 noundef %11)
  %14 = load i64, ptr @_tx_timer_created_count, align 8, !tbaa !9
  %.038 = load ptr, ptr @_tx_timer_created_ptr, align 8, !tbaa !11
  %15 = icmp eq i64 %14, 0
  %16 = icmp eq ptr %.038, %0
  %or.cond2939 = select i1 %15, i1 true, i1 %16
  br i1 %or.cond2939, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.041 = phi ptr [ %.0, %.lr.ph ], [ %.038, %10 ]
  %.02540 = phi i64 [ %18, %.lr.ph ], [ 0, %10 ]
  %17 = getelementptr inbounds i8, ptr %.041, i64 72
  %18 = add nuw i64 %.02540, 1
  %.0 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = icmp uge i64 %18, %14
  %20 = icmp eq ptr %.0, %0
  %or.cond29 = select i1 %19, i1 true, i1 %20
  br i1 %or.cond29, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %10
  %.lcssa = phi i1 [ %16, %10 ], [ %20, %.lr.ph ]
  %21 = tail call i32 @__disable_interrupts()
  %22 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  %23 = add i32 %22, -1
  store volatile i32 %23, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  tail call void @__restore_interrupt(i32 noundef %21)
  tail call void @_tx_thread_system_preempt_check() #3
  br i1 %.lcssa, label %.thread36, label %24

24:                                               ; preds = %._crit_edge
  %25 = icmp eq i64 %4, 0
  br i1 %25, label %.thread36, label %26

26:                                               ; preds = %24
  %or.cond = icmp ult i32 %6, 2
  br i1 %or.cond, label %27, label %40

27:                                               ; preds = %26
  %28 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !11
  %29 = icmp eq ptr %28, @_tx_timer_thread
  %spec.select31 = select i1 %29, i32 19, i32 0
  %30 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %31 = tail call i32 @_tx_ipsr_get()
  %32 = zext i32 %31 to i64
  %33 = or i64 %30, %32
  %.not28 = icmp eq i64 %33, 0
  br i1 %.not28, label %40, label %34

34:                                               ; preds = %27
  %35 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %36 = tail call i32 @_tx_ipsr_get()
  %37 = zext i32 %36 to i64
  %38 = or i64 %35, %37
  %39 = icmp ult i64 %38, 4042322160
  br i1 %39, label %.thread36, label %40

40:                                               ; preds = %34, %27, %26
  %.2 = phi i32 [ %spec.select31, %27 ], [ 23, %26 ], [ %spec.select31, %34 ]
  %41 = icmp eq i32 %.2, 0
  br i1 %41, label %42, label %.thread36

42:                                               ; preds = %40
  %43 = tail call i32 @_tx_timer_create(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, i32 noundef %6) #3
  br label %.thread36

.thread36:                                        ; preds = %34, %24, %._crit_edge, %8, %42, %40
  %.3 = phi i32 [ %43, %42 ], [ %.2, %40 ], [ 22, %24 ], [ 21, %._crit_edge ], [ 21, %8 ], [ 19, %34 ]
  ret i32 %.3
}

; 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_timer_create(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, i32 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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass