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

; 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 }
%struct.stStackMem_t = type { ptr, i32, 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7co_swapP13stCoRoutine_tS0_(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = 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) #5
  %11 = call noundef ptr @_Z22co_get_curr_thread_envv()
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.stCoRoutine_t, ptr %12, i32 0, i32 11
  store ptr %6, ptr %13, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.stCoRoutine_t, ptr %14, i32 0, i32 8
  %16 = load i8, ptr %15, align 4, !tbaa !14
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %23, label %18

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %19, i32 0, i32 3
  store ptr null, ptr %20, align 8, !tbaa !15
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %21, i32 0, i32 4
  store ptr null, ptr %22, align 8, !tbaa !17
  br label %49

23:                                               ; preds = %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %25, i32 0, i32 3
  store ptr %24, ptr %26, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.stCoRoutine_t, ptr %27, i32 0, i32 10
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  %30 = getelementptr inbounds %struct.stStackMem_t, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  store ptr %31, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.stCoRoutine_t, ptr %33, i32 0, i32 10
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = getelementptr inbounds %struct.stStackMem_t, ptr %35, i32 0, i32 0
  store ptr %32, ptr %36, align 8, !tbaa !19
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %38, i32 0, i32 4
  store ptr %37, ptr %39, align 8, !tbaa !17
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %48

42:                                               ; preds = %23
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = icmp ne ptr %43, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %42
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_Z17save_stack_bufferP13stCoRoutine_t(ptr noundef %47)
  br label %48

48:                                               ; preds = %46, %42, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %49

49:                                               ; preds = %48, %18
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.stCoRoutine_t, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.stCoRoutine_t, ptr %52, i32 0, i32 3
  call void @coctx_swap(ptr noundef %51, ptr noundef %53)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %54 = call noundef ptr @_Z22co_get_curr_thread_envv()
  store ptr %54, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %55, i32 0, i32 4
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  store ptr %57, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.stCoRoutineEnv_t, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  store ptr %60, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %92

63:                                               ; preds = %49
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %92

66:                                               ; preds = %63
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = icmp ne ptr %67, %68
  br i1 %69, label %70, label %92

70:                                               ; preds = %66
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.stCoRoutine_t, ptr %71, i32 0, i32 13
  %73 = load ptr, ptr %72, align 8, !tbaa !21
  %74 = icmp ne ptr %73, null
  br i1 %74, label %75, label %91

75:                                               ; preds = %70
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.stCoRoutine_t, ptr %76, i32 0, i32 12
  %78 = load i32, ptr %77, align 8, !tbaa !22
  %79 = icmp ugt i32 %78, 0
  br i1 %79, label %80, label %91

80:                                               ; preds = %75
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.stCoRoutine_t, ptr %81, i32 0, i32 11
  %83 = load ptr, ptr %82, align 8, !tbaa !9
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.stCoRoutine_t, ptr %84, i32 0, i32 13
  %86 = load ptr, ptr %85, align 8, !tbaa !21
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.stCoRoutine_t, ptr %87, i32 0, i32 12
  %89 = load i32, ptr %88, align 8, !tbaa !22
  %90 = zext i32 %89 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %83, ptr align 1 %86, i64 %90, i1 false)
  br label %91

91:                                               ; preds = %80, %75, %70
  br label %92

92:                                               ; preds = %91, %66, %63, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17save_stack_bufferP13stCoRoutine_t(ptr noundef) #2

declare void @coctx_swap(ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 = { 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 176}
!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 = !{!10, !7, i64 156}
!15 = !{!16, !6, i64 1040}
!16 = !{!"_ZTS16stCoRoutineEnv_t", !7, i64 0, !13, i64 1024, !6, i64 1032, !6, i64 1040, !6, i64 1048}
!17 = !{!16, !6, i64 1048}
!18 = !{!10, !6, i64 168}
!19 = !{!20, !6, i64 0}
!20 = !{!"_ZTS12stStackMem_t", !6, i64 0, !13, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!10, !6, i64 192}
!22 = !{!10, !13, i64 184}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z22co_get_curr_thread_envv() local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7co_swapP13stCoRoutine_tS0_(ptr noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca i8, align 1
  %4 = tail call noundef ptr @_Z22co_get_curr_thread_envv()
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #6
  %5 = getelementptr inbounds i8, ptr %0, i64 176
  store ptr %3, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 156
  %7 = load i8, ptr %6, align 4, !tbaa !13
  %.not = icmp eq i8 %7, 0
  %8 = getelementptr inbounds i8, ptr %4, i64 1040
  br i1 %.not, label %9, label %10

9:                                                ; preds = %2
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %8, i8 0, i64 16, i1 false)
  br label %16

10:                                               ; preds = %2
  store ptr %1, ptr %8, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %1, i64 168
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = load ptr, ptr %12, align 8, !tbaa !17
  store ptr %1, ptr %12, align 8, !tbaa !17
  %14 = getelementptr inbounds i8, ptr %4, i64 1048
  store ptr %13, ptr %14, align 8, !tbaa !19
  %.not33 = icmp eq ptr %13, null
  %.not34 = icmp eq ptr %13, %1
  %or.cond38 = or i1 %.not33, %.not34
  br i1 %or.cond38, label %16, label %15

15:                                               ; preds = %10
  call void @_Z17save_stack_bufferP13stCoRoutine_t(ptr noundef nonnull %13)
  br label %16

16:                                               ; preds = %10, %15, %9
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = getelementptr inbounds i8, ptr %1, i64 24
  call void @coctx_swap(ptr noundef nonnull %17, ptr noundef nonnull %18)
  %19 = call noundef ptr @_Z22co_get_curr_thread_envv()
  %20 = getelementptr inbounds i8, ptr %19, i64 1048
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = getelementptr inbounds i8, ptr %19, i64 1040
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = icmp eq ptr %21, null
  %25 = icmp eq ptr %23, null
  %.not35 = icmp eq ptr %21, %23
  %26 = or i1 %25, %.not35
  %or.cond39 = select i1 %24, i1 true, i1 %26
  br i1 %or.cond39, label %37, label %27

27:                                               ; preds = %16
  %28 = getelementptr inbounds i8, ptr %23, i64 192
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  %.not36 = icmp eq ptr %29, null
  br i1 %.not36, label %37, label %30

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %23, i64 184
  %32 = load i32, ptr %31, align 8, !tbaa !21
  %.not37 = icmp eq i32 %32, 0
  br i1 %.not37, label %37, label %33

33:                                               ; preds = %30
  %34 = getelementptr inbounds i8, ptr %23, i64 176
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = zext i32 %32 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %35, ptr nonnull align 1 %29, i64 %36, i1 false)
  br label %37

37:                                               ; preds = %27, %30, %33, %16
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #6
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17save_stack_bufferP13stCoRoutine_t(ptr noundef) local_unnamed_addr #2

declare void @coctx_swap(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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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, !7, i64 176}
!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 = !{!6, !8, i64 156}
!14 = !{!15, !7, i64 1040}
!15 = !{!"_ZTS16stCoRoutineEnv_t", !8, i64 0, !12, i64 1024, !7, i64 1032, !7, i64 1040, !7, i64 1048}
!16 = !{!6, !7, i64 168}
!17 = !{!18, !7, i64 0}
!18 = !{!"_ZTS12stStackMem_t", !7, i64 0, !12, i64 8, !7, i64 16, !7, i64 24}
!19 = !{!15, !7, i64 1048}
!20 = !{!6, !7, i64 192}
!21 = !{!6, !12, i64 184}


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