; LLVM IR from cjmcv/hpc :: coroutine/libco/libco/src (co_hook_sys_call)

; 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.stCoSysEnvArr_t = type { ptr, i64 }
%struct.stCoSysEnv_t = type { 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 }

@_ZL19g_sys_unsetenv_func = external hidden global ptr, align 8
@.str.26 = external hidden unnamed_addr constant [9 x i8], align 1
@_ZL11g_co_sysenv = external hidden global %struct.stCoSysEnvArr_t, align 8

; Function Attrs: nounwind
declare ptr @dlsym(ptr noundef, ptr noundef) #0

declare noundef zeroext i1 @_Z21co_is_enable_sys_hookv() #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #2

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL14co_sysenv_compPKvS0_(ptr noundef, ptr noundef) #4

declare noundef ptr @_Z7co_selfv() #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL17dup_co_sysenv_arrP15stCoSysEnvArr_t(ptr noundef) #4

; Function Attrs: inlinehint mustprogress uwtable
declare ptr @bsearch(ptr noundef nonnull, ptr noundef nonnull, i64 noundef, i64 noundef, ptr noundef nonnull) #5

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @unsetenv(ptr noundef nonnull %0) #4 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.stCoSysEnv_t, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr @_ZL19g_sys_unsetenv_func, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %13, label %11

11:                                               ; preds = %1
  %12 = call ptr @dlsym(ptr noundef inttoptr (i64 -1 to ptr), ptr noundef @.str.26) #6
  store ptr %12, ptr @_ZL19g_sys_unsetenv_func, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %11, %1
  %14 = invoke noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
          to label %15 unwind label %78

15:                                               ; preds = %13
  br i1 %14, label %16, label %71

16:                                               ; preds = %15
  %17 = load ptr, ptr @_ZL11g_co_sysenv, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %71

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %20 = invoke noundef ptr @_Z7co_selfv()
          to label %21 unwind label %78

21:                                               ; preds = %19
  store ptr %20, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %67

24:                                               ; preds = %21
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.stCoRoutine_t, ptr %25, i32 0, i32 9
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = icmp ne ptr %27, null
  br i1 %28, label %34, label %29

29:                                               ; preds = %24
  %30 = invoke noundef ptr @_ZL17dup_co_sysenv_arrP15stCoSysEnvArr_t(ptr noundef @_ZL11g_co_sysenv)
          to label %31 unwind label %78

31:                                               ; preds = %29
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.stCoRoutine_t, ptr %32, i32 0, i32 9
  store ptr %30, ptr %33, align 8, !tbaa !12
  br label %34

34:                                               ; preds = %31, %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.stCoRoutine_t, ptr %35, i32 0, i32 9
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  store ptr %37, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #6
  %38 = getelementptr inbounds %struct.stCoSysEnv_t, ptr %6, i32 0, i32 0
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %39, ptr %38, align 8, !tbaa !16
  %40 = getelementptr inbounds %struct.stCoSysEnv_t, ptr %6, i32 0, i32 1
  store ptr null, ptr %40, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.stCoSysEnvArr_t, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.stCoSysEnvArr_t, ptr %44, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !19
  %47 = invoke ptr @bsearch(ptr noundef %6, ptr noundef %43, i64 noundef %46, i64 noundef 16, ptr noundef @_ZL14co_sysenv_compPKvS0_)
          to label %48 unwind label %78

48:                                               ; preds = %34
  store ptr %47, ptr %7, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %63

51:                                               ; preds = %48
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.stCoSysEnv_t, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %62

56:                                               ; preds = %51
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.stCoSysEnv_t, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !18
  call void @free(ptr noundef %59) #6
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.stCoSysEnv_t, ptr %60, i32 0, i32 1
  store ptr null, ptr %61, align 8, !tbaa !18
  br label %62

62:                                               ; preds = %56, %51
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %64

63:                                               ; preds = %48
  store i32 0, ptr %8, align 4
  br label %64

64:                                               ; preds = %63, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  %65 = load i32, ptr %8, align 4
  switch i32 %65, label %68 [
    i32 0, label %66
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66, %21
  store i32 0, ptr %8, align 4
  br label %68

68:                                               ; preds = %67, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %69 = load i32, ptr %8, align 4
  switch i32 %69, label %81 [
    i32 0, label %70
    i32 1, label %76
  ]

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70, %16, %15
  %72 = load ptr, ptr @_ZL19g_sys_unsetenv_func, align 8, !tbaa !5
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = invoke noundef i32 %72(ptr noundef %73)
          to label %75 unwind label %78

75:                                               ; preds = %71
  store i32 %74, ptr %2, align 4
  br label %76

76:                                               ; preds = %75, %68
  %77 = load i32, ptr %2, align 4
  ret i32 %77

78:                                               ; preds = %71, %34, %29, %19, %13
  %79 = landingpad { ptr, i32 }
          catch ptr null
  %80 = extractvalue { ptr, i32 } %79, 0
  call void @__clang_call_terminate(ptr %80) #7
  unreachable

81:                                               ; preds = %68
  unreachable
}

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 = { "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 = { noinline noreturn nounwind uwtable "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 willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"_ZTS15stCoSysEnvArr_t", !6, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 160}
!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, !15, i64 184, !6, i64 192, !7, i64 200}
!14 = !{!"_ZTS7coctx_t", !7, i64 0, !11, i64 112, !6, i64 120}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTS12stCoSysEnv_t", !6, i64 0, !6, i64 8}
!18 = !{!17, !6, i64 8}
!19 = !{!10, !11, i64 8}


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

%struct.stCoSysEnvArr_t = type { ptr, i64 }
%struct.stCoSysEnv_t = type { ptr, ptr }

@_ZL19g_sys_unsetenv_func = external hidden local_unnamed_addr global ptr, align 8
@.str.26 = external hidden unnamed_addr constant [9 x i8], align 1
@_ZL11g_co_sysenv = external hidden global %struct.stCoSysEnvArr_t, align 8

; Function Attrs: nounwind
declare ptr @dlsym(ptr noundef, ptr noundef) local_unnamed_addr #0

declare noundef zeroext i1 @_Z21co_is_enable_sys_hookv() local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL14co_sysenv_compPKvS0_(ptr noundef, ptr noundef) #5

declare noundef ptr @_Z7co_selfv() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL17dup_co_sysenv_arrP15stCoSysEnvArr_t(ptr noundef) local_unnamed_addr #5

; Function Attrs: inlinehint mustprogress uwtable
declare ptr @bsearch(ptr noundef nonnull, ptr noundef nonnull, i64 noundef, i64 noundef, ptr noundef nonnull) local_unnamed_addr #6

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @unsetenv(ptr noundef nonnull %0) local_unnamed_addr #5 personality ptr @__gxx_personality_v0 {
  %2 = alloca %struct.stCoSysEnv_t, align 8
  %3 = load ptr, ptr @_ZL19g_sys_unsetenv_func, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %6

4:                                                ; preds = %1
  %5 = tail call ptr @dlsym(ptr noundef nonnull inttoptr (i64 -1 to ptr), ptr noundef nonnull @.str.26) #7
  store ptr %5, ptr @_ZL19g_sys_unsetenv_func, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %4, %1
  %7 = invoke noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
          to label %8 unwind label %35

8:                                                ; preds = %6
  %9 = load ptr, ptr @_ZL11g_co_sysenv, align 8
  %10 = icmp ne ptr %9, null
  %or.cond = select i1 %7, i1 %10, i1 false
  br i1 %or.cond, label %11, label %.thread

11:                                               ; preds = %8
  %12 = invoke noundef ptr @_Z7co_selfv()
          to label %13 unwind label %35

13:                                               ; preds = %11
  %.not20 = icmp eq ptr %12, null
  br i1 %.not20, label %.thread, label %14

14:                                               ; preds = %13
  %15 = getelementptr inbounds i8, ptr %12, i64 160
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %.not21 = icmp eq ptr %16, null
  br i1 %.not21, label %17, label %19

17:                                               ; preds = %14
  %18 = tail call noundef ptr @_ZL17dup_co_sysenv_arrP15stCoSysEnvArr_t(ptr noundef nonnull @_ZL11g_co_sysenv)
  store ptr %18, ptr %15, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %17, %14
  %20 = phi ptr [ %18, %17 ], [ %16, %14 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #7
  store ptr %0, ptr %2, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr null, ptr %21, align 8, !tbaa !16
  %22 = load ptr, ptr %20, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %20, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !19
  %25 = invoke ptr @bsearch(ptr noundef %2, ptr noundef %22, i64 noundef %24, i64 noundef 16, ptr noundef @_ZL14co_sysenv_compPKvS0_)
          to label %26 unwind label %35

26:                                               ; preds = %19
  %.not22 = icmp eq ptr %25, null
  br i1 %.not22, label %.critedge, label %27

27:                                               ; preds = %26
  %28 = getelementptr inbounds i8, ptr %25, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %.not23 = icmp eq ptr %29, null
  br i1 %.not23, label %31, label %30

30:                                               ; preds = %27
  call void @free(ptr noundef nonnull %29) #7
  store ptr null, ptr %28, align 8, !tbaa !16
  br label %31

.critedge:                                        ; preds = %26
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #7
  br label %.thread

31:                                               ; preds = %30, %27
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #7
  br label %34

.thread:                                          ; preds = %13, %.critedge, %8
  %32 = load ptr, ptr @_ZL19g_sys_unsetenv_func, align 8, !tbaa !5
  %33 = invoke noundef i32 %32(ptr noundef nonnull %0)
          to label %34 unwind label %35

34:                                               ; preds = %31, %.thread
  %.3 = phi i32 [ 0, %31 ], [ %33, %.thread ]
  ret i32 %.3

35:                                               ; preds = %.thread, %19, %11, %6
  %36 = landingpad { ptr, i32 }
          catch ptr null
  %37 = extractvalue { ptr, i32 } %36, 0
  call void @__clang_call_terminate(ptr %37) #8
  unreachable
}

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 = { "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 = { noinline noreturn nounwind uwtable "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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 = { inlinehint 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 #7 = { nounwind }
attributes #8 = { noreturn 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 160}
!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, !6, i64 0}
!15 = !{!"_ZTS12stCoSysEnv_t", !6, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 8}
!17 = !{!18, !6, i64 0}
!18 = !{!"_ZTS15stCoSysEnvArr_t", !6, i64 0, !12, i64 8}
!19 = !{!18, !12, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass