; LLVM IR from eclipse-threadx/threadx :: ports_arch/ARMv7-M/threadx_modules/ac6/module_lib/src/txm_module_thread_shell_e_c7b95a5c (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_THREAD_ENTRY_INFO_STRUCT = type { ptr, ptr, ptr, ptr, ptr, i64, ptr, i32, ptr, ptr, ptr, ptr }

@txm_heap = external dso_local global [512 x i8], align 8
@_txm_module_entry_info = external dso_local global ptr, align 8
@_txm_module_kernel_call_dispatcher = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @_txm_module_thread_shell_entry(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.TXM_MODULE_THREAD_ENTRY_INFO_STRUCT, ptr %6, i32 0, i32 7
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %25

10:                                               ; preds = %2
  call void @_txm_module_initialize(ptr noundef @txm_heap, ptr noundef getelementptr inbounds ([512 x i8], ptr @txm_heap, i64 0, i64 511))
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr @_txm_module_entry_info, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.TXM_MODULE_THREAD_ENTRY_INFO_STRUCT, ptr %12, i32 0, i32 11
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  store ptr %14, ptr @_txm_module_kernel_call_dispatcher, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %19, %10
  %16 = load ptr, ptr @_txm_module_kernel_call_dispatcher, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  %18 = xor i1 %17, true
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  br label %15, !llvm.loop !14

20:                                               ; preds = %15
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TXM_MODULE_THREAD_ENTRY_INFO_STRUCT, ptr %21, i32 0, i32 8
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = call i32 @_txe_thread_resume(ptr noundef %23)
  br label %25

25:                                               ; preds = %20, %2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TXM_MODULE_THREAD_ENTRY_INFO_STRUCT, ptr %26, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  store ptr %28, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %34

31:                                               ; preds = %25
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void %32(ptr noundef %33, i32 noundef 0)
  br label %34

34:                                               ; preds = %31, %25
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TXM_MODULE_THREAD_ENTRY_INFO_STRUCT, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TXM_MODULE_THREAD_ENTRY_INFO_STRUCT, ptr %38, i32 0, i32 5
  %40 = load i64, ptr %39, align 8, !tbaa !19
  call void %37(i64 noundef %40)
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TXM_MODULE_THREAD_ENTRY_INFO_STRUCT, ptr %41, i32 0, i32 6
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  store ptr %43, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %49

46:                                               ; preds = %34
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  call void %47(ptr noundef %48, i32 noundef 1)
  br label %49

49:                                               ; preds = %46, %34
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = call i32 @_txm_module_thread_system_suspend(ptr noundef %50)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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 void @_txm_module_initialize(ptr noundef, ptr noundef) #2

declare i32 @_txe_thread_resume(ptr noundef) #2

declare i32 @_txm_module_thread_system_suspend(ptr 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 56}
!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 = !{!10, !6, i64 88}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!10, !6, i64 64}
!17 = !{!10, !6, i64 48}
!18 = !{!10, !6, i64 32}
!19 = !{!10, !11, i64 40}


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

@txm_heap = external dso_local global [512 x i8], align 8
@_txm_module_entry_info = external dso_local local_unnamed_addr global ptr, align 8
@_txm_module_kernel_call_dispatcher = external dso_local local_unnamed_addr global ptr, align 8

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

5:                                                ; preds = %2
  tail call void @_txm_module_initialize(ptr noundef nonnull @txm_heap, ptr noundef nonnull getelementptr inbounds (i8, ptr @txm_heap, i64 511)) #2
  store ptr %1, ptr @_txm_module_entry_info, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %1, i64 88
  %7 = load ptr, ptr %6, align 8, !tbaa !13
  store ptr %7, ptr @_txm_module_kernel_call_dispatcher, align 8, !tbaa !12
  %.not16 = icmp eq ptr %7, null
  br i1 %.not16, label %.split, label %8, !llvm.loop !14

.split:                                           ; preds = %5, %.split
  br label %.split

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %1, i64 64
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  %11 = tail call i32 @_txe_thread_resume(ptr noundef %10) #2
  br label %12

12:                                               ; preds = %8, %2
  %13 = getelementptr inbounds i8, ptr %1, i64 48
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %.not17 = icmp eq ptr %14, null
  br i1 %.not17, label %16, label %15

15:                                               ; preds = %12
  tail call void %14(ptr noundef %0, i32 noundef 0) #2
  br label %16

16:                                               ; preds = %15, %12
  %17 = getelementptr inbounds i8, ptr %1, i64 32
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %1, i64 40
  %20 = load i64, ptr %19, align 8, !tbaa !19
  tail call void %18(i64 noundef %20) #2
  %21 = load ptr, ptr %13, align 8, !tbaa !17
  %.not18 = icmp eq ptr %21, null
  br i1 %.not18, label %23, label %22

22:                                               ; preds = %16
  tail call void %21(ptr noundef %0, i32 noundef 1) #2
  br label %23

23:                                               ; preds = %22, %16
  %24 = tail call i32 @_txm_module_thread_system_suspend(ptr noundef %0) #2
  ret void
}

declare void @_txm_module_initialize(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @_txe_thread_resume(ptr noundef) local_unnamed_addr #1

declare i32 @_txm_module_thread_system_suspend(ptr noundef) local_unnamed_addr #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 = { "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 = { 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 56}
!6 = !{!"TXM_MODULE_THREAD_ENTRY_INFO_STRUCT", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !11, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 88}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !7, i64 64}
!17 = !{!6, !7, i64 48}
!18 = !{!6, !7, i64 32}
!19 = !{!6, !10, i64 40}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass