; LLVM IR from mlcommons/tiny :: benchmark/interface/Middlewares/ST/threadx/common/src (tx_byte_pool_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_BYTE_POOL_STRUCT = type { i64, ptr, i64, i32, ptr, ptr, ptr, i64, ptr, ptr, i32, ptr, ptr }

@_tx_byte_pool_created_count = external global i64, align 8
@_tx_byte_pool_created_ptr = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_tx_byte_pool_create(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %16, i8 0, i64 104, i1 false)
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = udiv i64 %17, 8
  %19 = mul i64 %18, 8
  store i64 %19, ptr %8, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %21, i32 0, i32 1
  store ptr %20, ptr %22, align 8, !tbaa !11
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %24, i32 0, i32 6
  store ptr %23, ptr %25, align 8, !tbaa !14
  %26 = load i64, ptr %8, align 8, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %27, i32 0, i32 7
  store i64 %26, ptr %28, align 8, !tbaa !15
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %30, i32 0, i32 4
  store ptr %29, ptr %31, align 8, !tbaa !16
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %33, i32 0, i32 5
  store ptr %32, ptr %34, align 8, !tbaa !17
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = sub i64 %35, 16
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %37, i32 0, i32 2
  store i64 %36, ptr %38, align 8, !tbaa !18
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %39, i32 0, i32 3
  store i32 2, ptr %40, align 8, !tbaa !19
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %41, ptr %10, align 8, !tbaa !5
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = trunc i64 %43 to i32
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %42, i64 %45
  store ptr %46, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 -8
  store ptr %48, ptr %10, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %49, ptr %12, align 8, !tbaa !5
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %50, ptr %11, align 8, !tbaa !5
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %51, ptr %52, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 -8
  store ptr %54, ptr %10, align 8, !tbaa !5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %55, ptr %11, align 8, !tbaa !5
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %56, ptr %57, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %58, ptr %12, align 8, !tbaa !5
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %59, ptr %11, align 8, !tbaa !5
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %60, ptr %61, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %62, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 8
  store ptr %64, ptr %10, align 8, !tbaa !5
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %65, ptr %15, align 8, !tbaa !5
  %66 = load ptr, ptr %15, align 8, !tbaa !5
  store i64 4294962926, ptr %66, align 8, !tbaa !9
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %67, i32 0, i32 8
  store ptr null, ptr %68, align 8, !tbaa !20
  %69 = call i32 @__disable_interrupts()
  store i32 %69, ptr %9, align 4, !tbaa !21
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %70, i32 0, i32 0
  store i64 1113150533, ptr %71, align 8, !tbaa !22
  %72 = load i64, ptr @_tx_byte_pool_created_count, align 8, !tbaa !9
  %73 = icmp eq i64 %72, 0
  br i1 %73, label %74, label %82

74:                                               ; preds = %4
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %75, ptr @_tx_byte_pool_created_ptr, align 8, !tbaa !5
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %77, i32 0, i32 11
  store ptr %76, ptr %78, align 8, !tbaa !23
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %80, i32 0, i32 12
  store ptr %79, ptr %81, align 8, !tbaa !24
  br label %99

82:                                               ; preds = %4
  %83 = load ptr, ptr @_tx_byte_pool_created_ptr, align 8, !tbaa !5
  store ptr %83, ptr %13, align 8, !tbaa !5
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %84, i32 0, i32 12
  %86 = load ptr, ptr %85, align 8, !tbaa !24
  store ptr %86, ptr %14, align 8, !tbaa !5
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %88, i32 0, i32 12
  store ptr %87, ptr %89, align 8, !tbaa !24
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = load ptr, ptr %14, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %91, i32 0, i32 11
  store ptr %90, ptr %92, align 8, !tbaa !23
  %93 = load ptr, ptr %14, align 8, !tbaa !5
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %94, i32 0, i32 12
  store ptr %93, ptr %95, align 8, !tbaa !24
  %96 = load ptr, ptr %13, align 8, !tbaa !5
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %97, i32 0, i32 11
  store ptr %96, ptr %98, align 8, !tbaa !23
  br label %99

99:                                               ; preds = %82, %74
  %100 = load i64, ptr @_tx_byte_pool_created_count, align 8, !tbaa !9
  %101 = add i64 %100, 1
  store i64 %101, ptr @_tx_byte_pool_created_count, align 8, !tbaa !9
  %102 = load i32, ptr %9, align 4, !tbaa !21
  call void @__restore_interrupt(i32 noundef %102)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @__disable_interrupts() #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__restore_interrupt(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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, !6, i64 8}
!12 = !{!"TX_BYTE_POOL_STRUCT", !10, i64 0, !6, i64 8, !10, i64 16, !13, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !6, i64 64, !6, i64 72, !13, i64 80, !6, i64 88, !6, i64 96}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 48}
!15 = !{!12, !10, i64 56}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !6, i64 40}
!18 = !{!12, !10, i64 16}
!19 = !{!12, !13, i64 24}
!20 = !{!12, !6, i64 64}
!21 = !{!13, !13, i64 0}
!22 = !{!12, !10, i64 0}
!23 = !{!12, !6, i64 88}
!24 = !{!12, !6, i64 96}


; 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_byte_pool_created_count = external local_unnamed_addr global i64, align 8
@_tx_byte_pool_created_ptr = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @_tx_byte_pool_create(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(104) %0, i8 0, i64 104, i1 false)
  %5 = and i64 %3, -8
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %2, ptr %7, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  store i64 %5, ptr %8, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %2, ptr %9, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %2, ptr %10, align 8, !tbaa !15
  %11 = add i64 %5, -16
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %11, ptr %12, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 2, ptr %13, align 8, !tbaa !17
  %14 = and i64 %3, 4294967288
  %15 = getelementptr inbounds i8, ptr %2, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 -8
  store ptr %0, ptr %16, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %15, i64 -16
  store ptr %2, ptr %17, align 8, !tbaa !18
  store ptr %17, ptr %2, align 8, !tbaa !18
  %18 = getelementptr inbounds i8, ptr %2, i64 8
  store i64 4294962926, ptr %18, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr null, ptr %19, align 8, !tbaa !20
  %20 = tail call i32 @__disable_interrupts()
  store i64 1113150533, ptr %0, align 8, !tbaa !21
  %21 = load i64, ptr @_tx_byte_pool_created_count, align 8, !tbaa !19
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %28, label %23

23:                                               ; preds = %4
  %24 = load ptr, ptr @_tx_byte_pool_created_ptr, align 8, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %24, i64 96
  %26 = load ptr, ptr %25, align 8, !tbaa !22
  store ptr %0, ptr %25, align 8, !tbaa !22
  %27 = getelementptr inbounds i8, ptr %26, i64 88
  br label %28

28:                                               ; preds = %4, %23
  %.sink52 = phi ptr [ %27, %23 ], [ @_tx_byte_pool_created_ptr, %4 ]
  %.sink51 = phi ptr [ %24, %23 ], [ %0, %4 ]
  %.sink = phi ptr [ %26, %23 ], [ %0, %4 ]
  store ptr %0, ptr %.sink52, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %0, i64 88
  store ptr %.sink51, ptr %29, align 8
  %30 = getelementptr inbounds i8, ptr %0, i64 96
  store ptr %.sink, ptr %30, align 8
  %31 = add i64 %21, 1
  store i64 %31, ptr @_tx_byte_pool_created_count, align 8, !tbaa !19
  tail call void @__restore_interrupt(i32 noundef %20)
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @__disable_interrupts() local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__restore_interrupt(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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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, !10, i64 8}
!6 = !{!"TX_BYTE_POOL_STRUCT", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !7, i64 56, !10, i64 64, !10, i64 72, !11, i64 80, !10, i64 88, !10, i64 96}
!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, !10, i64 48}
!13 = !{!6, !7, i64 56}
!14 = !{!6, !10, i64 32}
!15 = !{!6, !10, i64 40}
!16 = !{!6, !7, i64 16}
!17 = !{!6, !11, i64 24}
!18 = !{!10, !10, i64 0}
!19 = !{!7, !7, i64 0}
!20 = !{!6, !10, i64 64}
!21 = !{!6, !7, i64 0}
!22 = !{!6, !10, i64 96}


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