; 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.rpchook_t = type { i32, %struct.sockaddr_in, i32, %struct.timeval, %struct.timeval }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%struct.timeval = type { i64, i64 }

@_ZL21g_sys_setsockopt_func = external hidden global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [11 x i8], align 1

; 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL9get_by_fdi(i32 noundef) #4

; 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) #5

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @setsockopt(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #6 personality ptr @__gxx_personality_v0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !5
  %14 = load ptr, ptr @_ZL21g_sys_setsockopt_func, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %18, label %16

16:                                               ; preds = %5
  %17 = call ptr @dlsym(ptr noundef inttoptr (i64 -1 to ptr), ptr noundef @.str.20) #7
  store ptr %17, ptr @_ZL21g_sys_setsockopt_func, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %16, %5
  %19 = invoke noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
          to label %20 unwind label %67

20:                                               ; preds = %18
  br i1 %19, label %30, label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr @_ZL21g_sys_setsockopt_func, align 8, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !5
  %26 = load ptr, ptr %10, align 8, !tbaa !9
  %27 = load i32, ptr %11, align 4, !tbaa !5
  %28 = invoke noundef i32 %22(i32 noundef %23, i32 noundef %24, i32 noundef %25, ptr noundef %26, i32 noundef %27)
          to label %29 unwind label %67

29:                                               ; preds = %21
  store i32 %28, ptr %6, align 4
  br label %65

30:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = invoke noundef ptr @_ZL9get_by_fdi(i32 noundef %31)
          to label %33 unwind label %67

33:                                               ; preds = %30
  store ptr %32, ptr %12, align 8, !tbaa !9
  %34 = load ptr, ptr %12, align 8, !tbaa !9
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %56

36:                                               ; preds = %33
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = icmp eq i32 1, %37
  br i1 %38, label %39, label %56

39:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %40 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %40, ptr %13, align 8, !tbaa !9
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = icmp eq i32 20, %41
  br i1 %42, label %43, label %47

43:                                               ; preds = %39
  %44 = load ptr, ptr %12, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.rpchook_t, ptr %44, i32 0, i32 3
  %46 = load ptr, ptr %13, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %45, ptr align 8 %46, i64 16, i1 false)
  br label %55

47:                                               ; preds = %39
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = icmp eq i32 21, %48
  br i1 %49, label %50, label %54

50:                                               ; preds = %47
  %51 = load ptr, ptr %12, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.rpchook_t, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %13, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %52, ptr align 8 %53, i64 16, i1 false)
  br label %54

54:                                               ; preds = %50, %47
  br label %55

55:                                               ; preds = %54, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  br label %56

56:                                               ; preds = %55, %36, %33
  %57 = load ptr, ptr @_ZL21g_sys_setsockopt_func, align 8, !tbaa !9
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = load ptr, ptr %10, align 8, !tbaa !9
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = invoke noundef i32 %57(i32 noundef %58, i32 noundef %59, i32 noundef %60, ptr noundef %61, i32 noundef %62)
          to label %64 unwind label %67

64:                                               ; preds = %56
  store i32 %63, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %65

65:                                               ; preds = %64, %29
  %66 = load i32, ptr %6, align 4
  ret i32 %66

67:                                               ; preds = %56, %30, %21, %18
  %68 = landingpad { ptr, i32 }
          catch ptr null
  %69 = extractvalue { ptr, i32 } %68, 0
  call void @__clang_call_terminate(ptr %69) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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

@_ZL21g_sys_setsockopt_func = external hidden local_unnamed_addr global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [11 x i8], align 1

; 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL9get_by_fdi(i32 noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @setsockopt(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #5 personality ptr @__gxx_personality_v0 {
  %6 = load ptr, ptr @_ZL21g_sys_setsockopt_func, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %7, label %9

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

9:                                                ; preds = %7, %5
  %10 = invoke noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
          to label %11 unwind label %22

11:                                               ; preds = %9
  br i1 %10, label %12, label %.invoke

12:                                               ; preds = %11
  %13 = tail call noundef ptr @_ZL9get_by_fdi(i32 noundef %0)
  %14 = icmp ne ptr %13, null
  %15 = icmp eq i32 %1, 1
  %or.cond = and i1 %15, %14
  br i1 %or.cond, label %16, label %.invoke

16:                                               ; preds = %12
  switch i32 %2, label %.invoke [
    i32 20, label %.sink.split
    i32 21, label %17
  ]

17:                                               ; preds = %16
  br label %.sink.split

.sink.split:                                      ; preds = %16, %17
  %.sink23 = phi i64 [ 40, %17 ], [ 24, %16 ]
  %18 = getelementptr inbounds i8, ptr %13, i64 %.sink23
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef nonnull align 8 dereferenceable(16) %3, i64 16, i1 false)
  br label %.invoke

.invoke:                                          ; preds = %12, %16, %.sink.split, %11
  %19 = load ptr, ptr @_ZL21g_sys_setsockopt_func, align 8, !tbaa !5
  %20 = invoke noundef i32 %19(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4)
          to label %21 unwind label %22

21:                                               ; preds = %.invoke
  ret i32 %20

22:                                               ; preds = %.invoke, %9
  %23 = landingpad { ptr, i32 }
          catch ptr null
  %24 = extractvalue { ptr, i32 } %23, 0
  tail call void @__clang_call_terminate(ptr %24) #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 = { inlinehint 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass