; LLVM IR from eclipse-threadx/threadx :: common_modules/module_lib/src (txm_module_callback_request_thread_entry)

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

@_txm_module_entry_info = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @_txm_module_callback_request_thread_entry(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 104, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = load ptr, ptr @_txm_module_entry_info, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.TXM_MODULE_THREAD_ENTRY_INFO_STRUCT, ptr %13, i32 0, i32 9
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %3, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %73, %1
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr %3, align 8, !tbaa !9
  %19 = call i32 @_txe_queue_receive(ptr noundef %18, ptr noundef %4, i64 noundef 4294967295)
  store i32 %19, ptr %11, align 4, !tbaa !14
  %20 = load i32, ptr %11, align 4, !tbaa !14
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  br label %74

23:                                               ; preds = %17
  %24 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !15
  store i64 %25, ptr %5, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %72, %23
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %73

29:                                               ; preds = %26
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = add i64 %30, -1
  store i64 %31, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !17
  switch i64 %33, label %71 [
    i64 0, label %34
    i64 1, label %40
    i64 2, label %47
    i64 3, label %54
    i64 4, label %61
  ]

34:                                               ; preds = %29
  %35 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  store ptr %36, ptr %6, align 8, !tbaa !9
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 3
  %39 = load i64, ptr %38, align 8, !tbaa !19
  call void %37(i64 noundef %39)
  br label %72

40:                                               ; preds = %29
  %41 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  store ptr %42, ptr %7, align 8, !tbaa !9
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 3
  %45 = load i64, ptr %44, align 8, !tbaa !19
  %46 = inttoptr i64 %45 to ptr
  call void %43(ptr noundef %46)
  br label %72

47:                                               ; preds = %29
  %48 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  store ptr %49, ptr %9, align 8, !tbaa !9
  %50 = load ptr, ptr %9, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 3
  %52 = load i64, ptr %51, align 8, !tbaa !19
  %53 = inttoptr i64 %52 to ptr
  call void %50(ptr noundef %53)
  br label %72

54:                                               ; preds = %29
  %55 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  store ptr %56, ptr %8, align 8, !tbaa !9
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 3
  %59 = load i64, ptr %58, align 8, !tbaa !19
  %60 = inttoptr i64 %59 to ptr
  call void %57(ptr noundef %60)
  br label %72

61:                                               ; preds = %29
  %62 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !18
  store ptr %63, ptr %10, align 8, !tbaa !9
  %64 = load ptr, ptr %10, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 3
  %66 = load i64, ptr %65, align 8, !tbaa !19
  %67 = inttoptr i64 %66 to ptr
  %68 = getelementptr inbounds %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, ptr %4, i32 0, i32 4
  %69 = load i64, ptr %68, align 8, !tbaa !20
  %70 = trunc i64 %69 to i32
  call void %64(ptr noundef %67, i32 noundef %70)
  br label %72

71:                                               ; preds = %29
  br label %72

72:                                               ; preds = %71, %61, %54, %47, %40, %34
  br label %26, !llvm.loop !21

73:                                               ; preds = %26
  br label %16

74:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

declare i32 @_txe_queue_receive(ptr noundef, ptr noundef, i64 noundef) #2

; 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 = { "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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 72}
!12 = !{!"TXM_MODULE_THREAD_ENTRY_INFO_STRUCT", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !13, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"TXM_MODULE_CALLBACK_MESSAGE_STRUCT", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!17 = !{!16, !6, i64 0}
!18 = !{!16, !10, i64 16}
!19 = !{!16, !6, i64 24}
!20 = !{!16, !6, i64 32}
!21 = distinct !{!21, !22}
!22 = !{!"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.TXM_MODULE_CALLBACK_MESSAGE_STRUCT = type { i64, i64, ptr, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }

@_txm_module_entry_info = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @_txm_module_callback_request_thread_entry(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.TXM_MODULE_CALLBACK_MESSAGE_STRUCT, align 8
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %2) #3
  %3 = load ptr, ptr @_txm_module_entry_info, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 72
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = call i32 @_txe_queue_receive(ptr noundef %5, ptr noundef nonnull %2, i64 noundef 4294967295) #3
  %.not12 = icmp eq i32 %6, 0
  br i1 %.not12, label %.lr.ph13, label %._crit_edge

.lr.ph13:                                         ; preds = %1
  %7 = getelementptr inbounds i8, ptr %2, i64 8
  %8 = getelementptr inbounds i8, ptr %2, i64 16
  %9 = getelementptr inbounds i8, ptr %2, i64 24
  %10 = getelementptr inbounds i8, ptr %2, i64 32
  br label %12

.loopexit:                                        ; preds = %37, %12
  %11 = call i32 @_txe_queue_receive(ptr noundef %5, ptr noundef nonnull %2, i64 noundef 4294967295) #3
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %._crit_edge

12:                                               ; preds = %.lr.ph13, %.loopexit
  %13 = load i64, ptr %7, align 8, !tbaa !13
  %.not910 = icmp eq i64 %13, 0
  br i1 %.not910, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12, %37
  %.011 = phi i64 [ %14, %37 ], [ %13, %12 ]
  %14 = add i64 %.011, -1
  %15 = load i64, ptr %2, align 8, !tbaa !15
  switch i64 %15, label %37 [
    i64 0, label %16
    i64 1, label %19
    i64 2, label %23
    i64 3, label %27
    i64 4, label %31
  ]

16:                                               ; preds = %.lr.ph
  %17 = load ptr, ptr %8, align 8, !tbaa !16
  %18 = load i64, ptr %9, align 8, !tbaa !17
  call void %17(i64 noundef %18) #3
  br label %37

19:                                               ; preds = %.lr.ph
  %20 = load ptr, ptr %8, align 8, !tbaa !16
  %21 = load i64, ptr %9, align 8, !tbaa !17
  %22 = inttoptr i64 %21 to ptr
  call void %20(ptr noundef %22) #3
  br label %37

23:                                               ; preds = %.lr.ph
  %24 = load ptr, ptr %8, align 8, !tbaa !16
  %25 = load i64, ptr %9, align 8, !tbaa !17
  %26 = inttoptr i64 %25 to ptr
  call void %24(ptr noundef %26) #3
  br label %37

27:                                               ; preds = %.lr.ph
  %28 = load ptr, ptr %8, align 8, !tbaa !16
  %29 = load i64, ptr %9, align 8, !tbaa !17
  %30 = inttoptr i64 %29 to ptr
  call void %28(ptr noundef %30) #3
  br label %37

31:                                               ; preds = %.lr.ph
  %32 = load ptr, ptr %8, align 8, !tbaa !16
  %33 = load i64, ptr %9, align 8, !tbaa !17
  %34 = inttoptr i64 %33 to ptr
  %35 = load i64, ptr %10, align 8, !tbaa !18
  %36 = trunc i64 %35 to i32
  call void %32(ptr noundef %34, i32 noundef %36) #3
  br label %37

37:                                               ; preds = %.lr.ph, %31, %27, %23, %19, %16
  %.not9 = icmp eq i64 %14, 0
  br i1 %.not9, label %.loopexit, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.loopexit, %1
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %2) #3
  ret void
}

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

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 72}
!10 = !{!"TXM_MODULE_THREAD_ENTRY_INFO_STRUCT", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !12, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !11, i64 8}
!14 = !{!"TXM_MODULE_CALLBACK_MESSAGE_STRUCT", !11, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96}
!15 = !{!14, !11, i64 0}
!16 = !{!14, !6, i64 16}
!17 = !{!14, !11, i64 24}
!18 = !{!14, !11, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass