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

; 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.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 }
%struct.stCoRoutineEnv_t = type { [128 x ptr], i32, ptr, ptr, ptr }

; 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: mustprogress uwtable
define dso_local void @_Z9co_resumeP13stCoRoutine_t(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.stCoRoutine_t, ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !14
  %13 = sub nsw i32 %12, 1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [128 x ptr], ptr %9, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %16, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.stCoRoutine_t, ptr %17, i32 0, i32 4
  %19 = load i8, ptr %18, align 8, !tbaa !16
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %28, label %21

21:                                               ; preds = %1
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.stCoRoutine_t, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call noundef i32 @_Z10coctx_makeP7coctx_tPFPvS1_S1_EPKvS5_(ptr noundef %23, ptr noundef @_ZL13CoRoutineFuncP13stCoRoutine_tPv, ptr noundef %24, ptr noundef null)
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.stCoRoutine_t, ptr %26, i32 0, i32 4
  store i8 1, ptr %27, align 8, !tbaa !16
  br label %28

28:                                               ; preds = %21, %1
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !14
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %33, align 8, !tbaa !14
  %36 = sext i32 %34 to i64
  %37 = getelementptr inbounds [128 x ptr], ptr %31, i64 0, i64 %36
  store ptr %29, ptr %37, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_Z7co_swapP13stCoRoutine_tS0_(ptr noundef %38, ptr noundef %39)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare noundef i32 @_Z10coctx_makeP7coctx_tPFPvS1_S1_EPKvS5_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL13CoRoutineFuncP13stCoRoutine_tPv(ptr noundef, ptr noundef) #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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++ TBAA"}
!9 = !{!10, !6, i64 0}
!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}
!16 = !{!10, !7, i64 152}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9co_resumeP13stCoRoutine_t(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 1024
  %4 = load i32, ptr %3, align 8, !tbaa !13
  %5 = add nsw i32 %4, -1
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [128 x ptr], ptr %2, i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %0, i64 152
  %10 = load i8, ptr %9, align 8, !tbaa !16
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %11, label %14

11:                                               ; preds = %1
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = tail call noundef i32 @_Z10coctx_makeP7coctx_tPFPvS1_S1_EPKvS5_(ptr noundef nonnull %12, ptr noundef nonnull @_ZL13CoRoutineFuncP13stCoRoutine_tPv, ptr noundef nonnull %0, ptr noundef null)
  store i8 1, ptr %9, align 8, !tbaa !16
  %.pre = load i32, ptr %3, align 8, !tbaa !13
  br label %14

14:                                               ; preds = %11, %1
  %15 = phi i32 [ %.pre, %11 ], [ %4, %1 ]
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %3, align 8, !tbaa !13
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds [128 x ptr], ptr %2, i64 0, i64 %17
  store ptr %0, ptr %18, align 8, !tbaa !15
  tail call void @_Z7co_swapP13stCoRoutine_tS0_(ptr noundef %8, ptr noundef nonnull %0)
  ret void
}

declare noundef i32 @_Z10coctx_makeP7coctx_tPFPvS1_S1_EPKvS5_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL13CoRoutineFuncP13stCoRoutine_tPv(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7co_swapP13stCoRoutine_tS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 #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" }

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


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