; 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.pollfd = type { i32, i16, i16 }
%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 }

@_ZL15g_sys_recv_func = external hidden global ptr, align 8
@.str.16 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [59 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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL9get_by_fdi(i32 noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

; Function Attrs: mustprogress uwtable
declare dso_local i32 @poll(ptr noundef, i64 noundef, i32 noundef) #6

declare void @_Z10co_log_errPKcz(ptr noundef, ...) #1

; Function Attrs: mustprogress uwtable
define dso_local i64 @recv(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) #6 {
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %struct.pollfd, align 4
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !11
  store i32 %3, ptr %9, align 4, !tbaa !5
  %16 = load ptr, ptr @_ZL15g_sys_recv_func, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %20, label %18

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

20:                                               ; preds = %18, %4
  %21 = call noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
  br i1 %21, label %29, label %22

22:                                               ; preds = %20
  %23 = load ptr, ptr @_ZL15g_sys_recv_func, align 8, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = load i64, ptr %8, align 8, !tbaa !11
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = call noundef i64 %23(i32 noundef %24, ptr noundef %25, i64 noundef %26, i32 noundef %27)
  store i64 %28, ptr %5, align 8
  br label %83

29:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = call noundef ptr @_ZL9get_by_fdi(i32 noundef %30)
  store ptr %31, ptr %10, align 8, !tbaa !9
  %32 = load ptr, ptr %10, align 8, !tbaa !9
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %40

34:                                               ; preds = %29
  %35 = load ptr, ptr %10, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.rpchook_t, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = and i32 2048, %37
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %47

40:                                               ; preds = %34, %29
  %41 = load ptr, ptr @_ZL15g_sys_recv_func, align 8, !tbaa !9
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  %44 = load i64, ptr %8, align 8, !tbaa !11
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = call noundef i64 %41(i32 noundef %42, ptr noundef %43, i64 noundef %44, i32 noundef %45)
  store i64 %46, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %82

47:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %48 = load ptr, ptr %10, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.rpchook_t, ptr %48, i32 0, i32 3
  %50 = getelementptr inbounds %struct.timeval, ptr %49, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !19
  %52 = mul nsw i64 %51, 1000
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.rpchook_t, ptr %53, i32 0, i32 3
  %55 = getelementptr inbounds %struct.timeval, ptr %54, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !20
  %57 = sdiv i64 %56, 1000
  %58 = add nsw i64 %52, %57
  %59 = trunc i64 %58 to i32
  store i32 %59, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  call void @llvm.memset.p0.i64(ptr align 4 %13, i8 0, i64 8, i1 false)
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = getelementptr inbounds %struct.pollfd, ptr %13, i32 0, i32 0
  store i32 %60, ptr %61, align 4, !tbaa !21
  %62 = getelementptr inbounds %struct.pollfd, ptr %13, i32 0, i32 1
  store i16 25, ptr %62, align 4, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  %63 = load i32, ptr %12, align 4, !tbaa !5
  %64 = call i32 @poll(ptr noundef %13, i64 noundef 1, i32 noundef %63)
  store i32 %64, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  %65 = load ptr, ptr @_ZL15g_sys_recv_func, align 8, !tbaa !9
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  %68 = load i64, ptr %8, align 8, !tbaa !11
  %69 = load i32, ptr %9, align 4, !tbaa !5
  %70 = call noundef i64 %65(i32 noundef %66, ptr noundef %67, i64 noundef %68, i32 noundef %69)
  store i64 %70, ptr %15, align 8, !tbaa !11
  %71 = load i64, ptr %15, align 8, !tbaa !11
  %72 = icmp slt i64 %71, 0
  br i1 %72, label %73, label %80

73:                                               ; preds = %47
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = load i64, ptr %15, align 8, !tbaa !11
  %76 = call ptr @__errno_location() #8
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = load i32, ptr %14, align 4, !tbaa !5
  %79 = load i32, ptr %12, align 4, !tbaa !5
  call void (ptr, ...) @_Z10co_log_errPKcz(ptr noundef @.str.35, i32 noundef %74, i64 noundef %75, i32 noundef %77, i32 noundef %78, i32 noundef %79)
  br label %80

80:                                               ; preds = %73, %47
  %81 = load i64, ptr %15, align 8, !tbaa !11
  store i64 %81, ptr %5, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %82

82:                                               ; preds = %80, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %83

83:                                               ; preds = %82, %22
  %84 = load i64, ptr %5, align 8
  ret i64 %84
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind willreturn memory(none) "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 = { 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 = { nounwind willreturn memory(none) }

!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}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS9rpchook_t", !6, i64 0, !15, i64 4, !6, i64 20, !18, i64 24, !18, i64 40}
!15 = !{!"_ZTS11sockaddr_in", !16, i64 0, !16, i64 2, !17, i64 4, !7, i64 8}
!16 = !{!"short", !7, i64 0}
!17 = !{!"_ZTS7in_addr", !6, i64 0}
!18 = !{!"_ZTS7timeval", !12, i64 0, !12, i64 8}
!19 = !{!14, !12, i64 24}
!20 = !{!14, !12, i64 32}
!21 = !{!22, !6, i64 0}
!22 = !{!"_ZTS6pollfd", !6, i64 0, !16, i64 4, !16, i64 6}
!23 = !{!22, !16, i64 4}


; 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.pollfd = type { i32, i16, i16 }

@_ZL15g_sys_recv_func = external hidden local_unnamed_addr global ptr, align 8
@.str.16 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [59 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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL9get_by_fdi(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local i32 @poll(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #5

declare void @_Z10co_log_errPKcz(ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @recv(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #5 {
  %5 = alloca %struct.pollfd, align 8
  %6 = load ptr, ptr @_ZL15g_sys_recv_func, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %7, label %9

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

9:                                                ; preds = %7, %4
  %10 = tail call noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
  br i1 %10, label %14, label %11

11:                                               ; preds = %9
  %12 = load ptr, ptr @_ZL15g_sys_recv_func, align 8, !tbaa !5
  %13 = tail call noundef i64 %12(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3)
  br label %39

14:                                               ; preds = %9
  %15 = tail call noundef ptr @_ZL9get_by_fdi(i32 noundef %0)
  %.not27 = icmp eq ptr %15, null
  br i1 %.not27, label %19, label %16

16:                                               ; preds = %14
  %17 = load i32, ptr %15, align 8, !tbaa !9
  %18 = and i32 %17, 2048
  %.not28 = icmp eq i32 %18, 0
  br i1 %.not28, label %22, label %19

19:                                               ; preds = %16, %14
  %20 = load ptr, ptr @_ZL15g_sys_recv_func, align 8, !tbaa !5
  %21 = tail call noundef i64 %20(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3)
  br label %39

22:                                               ; preds = %16
  %23 = getelementptr inbounds i8, ptr %15, i64 24
  %24 = load i64, ptr %23, align 8, !tbaa !17
  %25 = mul nsw i64 %24, 1000
  %26 = getelementptr inbounds i8, ptr %15, i64 32
  %27 = load i64, ptr %26, align 8, !tbaa !18
  %28 = sdiv i64 %27, 1000
  %29 = add nsw i64 %28, %25
  %30 = trunc i64 %29 to i32
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  store i64 107374182400, ptr %5, align 8
  store i32 %0, ptr %5, align 8, !tbaa !19
  %31 = call i32 @poll(ptr noundef nonnull %5, i64 noundef 1, i32 noundef %30)
  %32 = load ptr, ptr @_ZL15g_sys_recv_func, align 8, !tbaa !5
  %33 = call noundef i64 %32(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3)
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %22
  %36 = tail call ptr @__errno_location() #7
  %37 = load i32, ptr %36, align 4, !tbaa !21
  call void (ptr, ...) @_Z10co_log_errPKcz(ptr noundef nonnull @.str.35, i32 noundef %0, i64 noundef %33, i32 noundef %37, i32 noundef %31, i32 noundef %30)
  br label %38

38:                                               ; preds = %35, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  br label %39

39:                                               ; preds = %19, %38, %11
  %.1 = phi i64 [ %13, %11 ], [ %21, %19 ], [ %33, %38 ]
  ret i64 %.1
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nofree nosync nounwind willreturn memory(none) "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 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 = { nounwind willreturn memory(none) }

!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, !11, i64 0}
!10 = !{!"_ZTS9rpchook_t", !11, i64 0, !12, i64 4, !11, i64 20, !15, i64 24, !15, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS11sockaddr_in", !13, i64 0, !13, i64 2, !14, i64 4, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_ZTS7in_addr", !11, i64 0}
!15 = !{!"_ZTS7timeval", !16, i64 0, !16, i64 8}
!16 = !{!"long", !7, i64 0}
!17 = !{!10, !16, i64 24}
!18 = !{!10, !16, i64 32}
!19 = !{!20, !11, i64 0}
!20 = !{!"_ZTS6pollfd", !11, i64 0, !13, i64 4, !13, i64 6}
!21 = !{!11, !11, i64 0}


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