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

@_ZL17g_sys_getenv_func = external hidden global ptr, align 8
@.str.28 = external hidden unnamed_addr constant [7 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: 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 ptr @getenv(ptr noundef nonnull %0) #4 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.stCoSysEnv_t, align 8
  %6 = alloca ptr, 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 @_ZL17g_sys_getenv_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.28) #6
  store ptr %12, ptr @_ZL17g_sys_getenv_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 %63

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

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 %56

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 %63

21:                                               ; preds = %19
  store ptr %20, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #6
  %22 = getelementptr inbounds %struct.stCoSysEnv_t, ptr %5, i32 0, i32 0
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %23, ptr %22, align 8, !tbaa !12
  %24 = getelementptr inbounds %struct.stCoSysEnv_t, ptr %5, i32 0, i32 1
  store ptr null, ptr %24, align 8, !tbaa !14
  %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 !15
  %28 = icmp ne ptr %27, null
  br i1 %28, label %34, label %29

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

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 !15
  br label %34

34:                                               ; preds = %31, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #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 !15
  store ptr %37, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.stCoSysEnvArr_t, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.stCoSysEnvArr_t, ptr %41, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !19
  %44 = invoke ptr @bsearch(ptr noundef %5, ptr noundef %40, i64 noundef %43, i64 noundef 16, ptr noundef @_ZL14co_sysenv_compPKvS0_)
          to label %45 unwind label %63

45:                                               ; preds = %34
  store ptr %44, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %52

48:                                               ; preds = %45
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.stCoSysEnv_t, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  store ptr %51, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %53

52:                                               ; preds = %45
  store i32 0, ptr %8, align 4
  br label %53

53:                                               ; preds = %52, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %54 = load i32, ptr %8, align 4
  switch i32 %54, label %66 [
    i32 0, label %55
    i32 1, label %61
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55, %16, %15
  %57 = load ptr, ptr @_ZL17g_sys_getenv_func, align 8, !tbaa !5
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = invoke noundef ptr %57(ptr noundef %58)
          to label %60 unwind label %63

60:                                               ; preds = %56
  store ptr %59, ptr %2, align 8
  br label %61

61:                                               ; preds = %60, %53
  %62 = load ptr, ptr %2, align 8
  ret ptr %62

63:                                               ; preds = %56, %34, %29, %19, %13
  %64 = landingpad { ptr, i32 }
          catch ptr null
  %65 = extractvalue { ptr, i32 } %64, 0
  call void @__clang_call_terminate(ptr %65) #7
  unreachable

66:                                               ; preds = %53
  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 0}
!13 = !{!"_ZTS12stCoSysEnv_t", !6, i64 0, !6, i64 8}
!14 = !{!13, !6, i64 8}
!15 = !{!16, !6, i64 160}
!16 = !{!"_ZTS13stCoRoutine_t", !6, i64 0, !6, i64 8, !6, i64 16, !17, 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, !18, i64 184, !6, i64 192, !7, i64 200}
!17 = !{!"_ZTS7coctx_t", !7, i64 0, !11, i64 112, !6, i64 120}
!18 = !{!"int", !7, i64 0}
!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 }

@_ZL17g_sys_getenv_func = external hidden local_unnamed_addr global ptr, align 8
@.str.28 = external hidden unnamed_addr constant [7 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 uwtable
declare hidden noundef i32 @_ZL14co_sysenv_compPKvS0_(ptr noundef, ptr noundef) #4

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 #4

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local ptr @getenv(ptr noundef nonnull %0) local_unnamed_addr #4 personality ptr @__gxx_personality_v0 {
  %2 = alloca %struct.stCoSysEnv_t, align 8
  %3 = load ptr, ptr @_ZL17g_sys_getenv_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.28) #6
  store ptr %5, ptr @_ZL17g_sys_getenv_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 %33

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 %29

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

13:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #6
  store ptr %0, ptr %2, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr null, ptr %14, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %12, i64 160
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %.not13 = icmp eq ptr %16, null
  br i1 %.not13, label %17, label %19

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

19:                                               ; preds = %17, %13
  %20 = phi ptr [ %18, %17 ], [ %16, %13 ]
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %20, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !19
  %24 = invoke ptr @bsearch(ptr noundef %2, ptr noundef %21, i64 noundef %23, i64 noundef 16, ptr noundef @_ZL14co_sysenv_compPKvS0_)
          to label %25 unwind label %33

25:                                               ; preds = %19
  %.not14.not = icmp eq ptr %24, null
  br i1 %.not14.not, label %.thread, label %26

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

26:                                               ; preds = %25
  %27 = getelementptr inbounds i8, ptr %24, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #6
  br label %32

29:                                               ; preds = %.thread, %8
  %30 = load ptr, ptr @_ZL17g_sys_getenv_func, align 8, !tbaa !5
  %31 = invoke noundef ptr %30(ptr noundef nonnull %0)
          to label %32 unwind label %33

32:                                               ; preds = %26, %29
  %.1 = phi ptr [ %28, %26 ], [ %31, %29 ]
  ret ptr %.1

33:                                               ; preds = %29, %19, %11, %6
  %34 = landingpad { ptr, i32 }
          catch ptr null
  %35 = extractvalue { ptr, i32 } %34, 0
  call void @__clang_call_terminate(ptr %35) #7
  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 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 = !{!"_ZTS12stCoSysEnv_t", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!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, !16, 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 = !{!"int", !7, i64 0}
!17 = !{!18, !6, i64 0}
!18 = !{!"_ZTS15stCoSysEnvArr_t", !6, i64 0, !15, i64 8}
!19 = !{!18, !15, i64 8}


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