; LLVM IR from cjmcv/hpc :: coroutine/libco/libco/src/co_routine.ll (Z23co_init_curr_thread_envv)

; 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.stCoRoutineEnv_t = type { [128 x ptr], i32, ptr, ptr, ptr }
%struct.stCoRoutine_t = type { ptr, ptr, ptr, %struct.coctx_t, i8, i8, i8, i8, i8, ptr, ptr, ptr, i32, ptr, [1024 x %struct.stCoSpec_t] }
%struct.coctx_t = type { [14 x ptr], i64, ptr }
%struct.stCoSpec_t = type { ptr }

@_ZL15gCoEnvPerThread = external hidden thread_local global ptr, align 8

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

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z13co_create_envP16stCoRoutineEnv_tPK17stCoRoutineAttr_tPFPvS4_ES4_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z23co_init_curr_thread_envv() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 1056) #6
  %5 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_ZL15gCoEnvPerThread)
  store ptr %4, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #7
  %6 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_ZL15gCoEnvPerThread)
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %7, ptr %1, align 8, !tbaa !5
  %8 = load ptr, ptr %1, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %8, i32 0, i32 1
  store i32 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #7
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = call noundef ptr @_Z13co_create_envP16stCoRoutineEnv_tPK17stCoRoutineAttr_tPFPvS4_ES4_(ptr noundef %10, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %11, ptr %2, align 8, !tbaa !5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.stCoRoutine_t, ptr %12, i32 0, i32 6
  store i8 1, ptr %13, align 2, !tbaa !12
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %14, i32 0, i32 3
  store ptr null, ptr %15, align 8, !tbaa !16
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %16, i32 0, i32 4
  store ptr null, ptr %17, align 8, !tbaa !17
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.stCoRoutine_t, ptr %18, i32 0, i32 3
  %20 = call noundef i32 @_Z10coctx_initP7coctx_t(ptr noundef %19)
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 8, !tbaa !9
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds [128 x ptr], ptr %23, i64 0, i64 %28
  store ptr %21, ptr %29, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #7
  %30 = call noundef ptr @_Z10AllocEpollv()
  store ptr %30, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %1, align 8, !tbaa !5
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z8SetEpollP16stCoRoutineEnv_tP11stCoEpoll_t(ptr noundef %31, ptr noundef %32)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #7
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #3

declare noundef i32 @_Z10coctx_initP7coctx_t(ptr noundef) #4

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z10AllocEpollv() #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8SetEpollP16stCoRoutineEnv_tP11stCoEpoll_t(ptr noundef, ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(0,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 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { "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 #5 = { mustprogress 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 #6 = { nounwind allocsize(0,1) }
attributes #7 = { 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++ TBAA"}
!9 = !{!10, !11, i64 1024}
!10 = !{!"_ZTS16stCoRoutineEnv_t", !7, i64 0, !11, i64 1024, !6, i64 1032, !6, i64 1040, !6, i64 1048}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 154}
!13 = !{!"_ZTS13stCoRoutine_t", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !7, i64 152, !7, i64 153, !7, i64 154, !7, i64 155, !7, i64 156, !6, i64 160, !6, i64 168, !6, i64 176, !11, i64 184, !6, i64 192, !7, i64 200}
!14 = !{!"_ZTS7coctx_t", !7, i64 0, !15, i64 112, !6, i64 120}
!15 = !{!"long", !7, i64 0}
!16 = !{!10, !6, i64 1040}
!17 = !{!10, !6, i64 1048}


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

@_ZL15gCoEnvPerThread = external hidden thread_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z13co_create_envP16stCoRoutineEnv_tPK17stCoRoutineAttr_tPFPvS4_ES4_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z23co_init_curr_thread_envv() local_unnamed_addr #1 {
  %1 = tail call noalias dereferenceable_or_null(1056) ptr @calloc(i64 noundef 1, i64 noundef 1056) #6
  %2 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_ZL15gCoEnvPerThread)
  store ptr %1, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %1, i64 1024
  %4 = tail call noundef ptr @_Z13co_create_envP16stCoRoutineEnv_tPK17stCoRoutineAttr_tPFPvS4_ES4_(ptr noundef %1, ptr noundef null, ptr noundef null, ptr noundef null)
  %5 = getelementptr inbounds i8, ptr %4, i64 154
  store i8 1, ptr %5, align 2, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %1, i64 1040
  %7 = getelementptr inbounds i8, ptr %4, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, i8 0, i64 16, i1 false)
  %8 = tail call noundef i32 @_Z10coctx_initP7coctx_t(ptr noundef nonnull %7)
  %9 = load i32, ptr %3, align 8, !tbaa !14
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %3, align 8, !tbaa !14
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds [128 x ptr], ptr %1, i64 0, i64 %11
  store ptr %4, ptr %12, align 8, !tbaa !5
  %13 = tail call noundef ptr @_Z10AllocEpollv()
  tail call void @_Z8SetEpollP16stCoRoutineEnv_tP11stCoEpoll_t(ptr noundef %1, ptr noundef %13)
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

declare noundef i32 @_Z10coctx_initP7coctx_t(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z10AllocEpollv() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8SetEpollP16stCoRoutineEnv_tP11stCoEpoll_t(ptr noundef, ptr noundef) local_unnamed_addr #4

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { mustprogress 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind allocsize(0,1) }

!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++ TBAA"}
!9 = !{!10, !7, i64 154}
!10 = !{!"_ZTS13stCoRoutine_t", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !7, i64 152, !7, i64 153, !7, i64 154, !7, i64 155, !7, i64 156, !6, i64 160, !6, i64 168, !6, i64 176, !13, i64 184, !6, i64 192, !7, i64 200}
!11 = !{!"_ZTS7coctx_t", !7, i64 0, !12, i64 112, !6, i64 120}
!12 = !{!"long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 1024}
!15 = !{!"_ZTS16stCoRoutineEnv_t", !7, i64 0, !13, i64 1024, !6, i64 1032, !6, i64 1040, !6, i64 1048}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass