; LLVM IR from cjmcv/hpc :: coroutine/libco/libco/src/co_routine.ll (Z7co_freeP13stCoRoutine_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.stStackMem_t = type { ptr, i32, ptr, ptr }

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7co_freeP13stCoRoutine_t(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.stCoRoutine_t, ptr %3, i32 0, i32 8
  %5 = load i8, ptr %4, align 4, !tbaa !9
  %6 = icmp ne i8 %5, 0
  br i1 %6, label %16, label %7

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.stCoRoutine_t, ptr %8, i32 0, i32 10
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = getelementptr inbounds %struct.stStackMem_t, ptr %10, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  call void @free(ptr noundef %12) #2
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.stCoRoutine_t, ptr %13, i32 0, i32 10
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  call void @free(ptr noundef %15) #2
  br label %16

16:                                               ; preds = %7, %1
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %17) #2
  ret void
}

attributes #0 = { nounwind "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 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !7, i64 156}
!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, !6, i64 168}
!15 = !{!16, !6, i64 24}
!16 = !{!"_ZTS12stStackMem_t", !6, i64 0, !13, i64 8, !6, i64 16, !6, i64 24}


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local void @_Z7co_freeP13stCoRoutine_t(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 156
  %3 = load i8, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %4, label %10

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 168
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  tail call void @free(ptr noundef %8) #2
  %9 = load ptr, ptr %5, align 8, !tbaa !13
  tail call void @free(ptr noundef %9) #2
  br label %10

10:                                               ; preds = %4, %1
  tail call void @free(ptr noundef nonnull %0) #2
  ret void
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 nounwind willreturn 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 = { 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, !8, i64 156}
!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, !7, i64 168}
!14 = !{!15, !7, i64 24}
!15 = !{!"_ZTS12stStackMem_t", !7, i64 0, !12, i64 8, !7, i64 16, !7, i64 24}


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