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

@_ZL17g_sys_sendto_func = external hidden global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [7 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

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

21:                                               ; preds = %6
  %22 = call ptr @dlsym(ptr noundef inttoptr (i64 -1 to ptr), ptr noundef @.str.10) #7
  store ptr %22, ptr @_ZL17g_sys_sendto_func, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %21, %6
  %24 = call noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
  br i1 %24, label %34, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr @_ZL17g_sys_sendto_func, align 8, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = load ptr, ptr %9, align 8, !tbaa !9
  %29 = load i64, ptr %10, align 8, !tbaa !11
  %30 = load i32, ptr %11, align 4, !tbaa !5
  %31 = load ptr, ptr %12, align 8, !tbaa !9
  %32 = load i32, ptr %13, align 4, !tbaa !5
  %33 = call noundef i64 %26(i32 noundef %27, ptr noundef %28, i64 noundef %29, i32 noundef %30, ptr noundef %31, i32 noundef %32)
  store i64 %33, ptr %7, align 8
  br label %98

34:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = call noundef ptr @_ZL9get_by_fdi(i32 noundef %35)
  store ptr %36, ptr %14, align 8, !tbaa !9
  %37 = load ptr, ptr %14, align 8, !tbaa !9
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %45

39:                                               ; preds = %34
  %40 = load ptr, ptr %14, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.rpchook_t, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !13
  %43 = and i32 2048, %42
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %54

45:                                               ; preds = %39, %34
  %46 = load ptr, ptr @_ZL17g_sys_sendto_func, align 8, !tbaa !9
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !9
  %49 = load i64, ptr %10, align 8, !tbaa !11
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = load ptr, ptr %12, align 8, !tbaa !9
  %52 = load i32, ptr %13, align 4, !tbaa !5
  %53 = call noundef i64 %46(i32 noundef %47, ptr noundef %48, i64 noundef %49, i32 noundef %50, ptr noundef %51, i32 noundef %52)
  store i64 %53, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %97

54:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #7
  %55 = load ptr, ptr @_ZL17g_sys_sendto_func, align 8, !tbaa !9
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !9
  %58 = load i64, ptr %10, align 8, !tbaa !11
  %59 = load i32, ptr %11, align 4, !tbaa !5
  %60 = load ptr, ptr %12, align 8, !tbaa !9
  %61 = load i32, ptr %13, align 4, !tbaa !5
  %62 = call noundef i64 %55(i32 noundef %56, ptr noundef %57, i64 noundef %58, i32 noundef %59, ptr noundef %60, i32 noundef %61)
  store i64 %62, ptr %16, align 8, !tbaa !11
  %63 = load i64, ptr %16, align 8, !tbaa !11
  %64 = icmp slt i64 %63, 0
  br i1 %64, label %65, label %95

65:                                               ; preds = %54
  %66 = call ptr @__errno_location() #8
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = icmp eq i32 11, %67
  br i1 %68, label %69, label %95

69:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #7
  %70 = load ptr, ptr %14, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.rpchook_t, ptr %70, i32 0, i32 4
  %72 = getelementptr inbounds %struct.timeval, ptr %71, i32 0, i32 0
  %73 = load i64, ptr %72, align 8, !tbaa !19
  %74 = mul nsw i64 %73, 1000
  %75 = load ptr, ptr %14, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.rpchook_t, ptr %75, i32 0, i32 4
  %77 = getelementptr inbounds %struct.timeval, ptr %76, i32 0, i32 1
  %78 = load i64, ptr %77, align 8, !tbaa !20
  %79 = sdiv i64 %78, 1000
  %80 = add nsw i64 %74, %79
  %81 = trunc i64 %80 to i32
  store i32 %81, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #7
  call void @llvm.memset.p0.i64(ptr align 4 %18, i8 0, i64 8, i1 false)
  %82 = load i32, ptr %8, align 4, !tbaa !5
  %83 = getelementptr inbounds %struct.pollfd, ptr %18, i32 0, i32 0
  store i32 %82, ptr %83, align 4, !tbaa !21
  %84 = getelementptr inbounds %struct.pollfd, ptr %18, i32 0, i32 1
  store i16 28, ptr %84, align 4, !tbaa !23
  %85 = load i32, ptr %17, align 4, !tbaa !5
  %86 = call i32 @poll(ptr noundef %18, i64 noundef 1, i32 noundef %85)
  %87 = load ptr, ptr @_ZL17g_sys_sendto_func, align 8, !tbaa !9
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = load ptr, ptr %9, align 8, !tbaa !9
  %90 = load i64, ptr %10, align 8, !tbaa !11
  %91 = load i32, ptr %11, align 4, !tbaa !5
  %92 = load ptr, ptr %12, align 8, !tbaa !9
  %93 = load i32, ptr %13, align 4, !tbaa !5
  %94 = call noundef i64 %87(i32 noundef %88, ptr noundef %89, i64 noundef %90, i32 noundef %91, ptr noundef %92, i32 noundef %93)
  store i64 %94, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #7
  br label %95

95:                                               ; preds = %69, %65, %54
  %96 = load i64, ptr %16, align 8, !tbaa !11
  store i64 %96, ptr %7, align 8
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #7
  br label %97

97:                                               ; preds = %95, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  br label %98

98:                                               ; preds = %97, %25
  %99 = load i64, ptr %7, align 8
  ret i64 %99
}

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 40}
!20 = !{!14, !12, i64 48}
!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 }

@_ZL17g_sys_sendto_func = external hidden local_unnamed_addr global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [7 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

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

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

11:                                               ; preds = %9, %6
  %12 = tail call noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
  br i1 %12, label %16, label %13

13:                                               ; preds = %11
  %14 = load ptr, ptr @_ZL17g_sys_sendto_func, align 8, !tbaa !5
  %15 = tail call noundef i64 %14(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5)
  br label %44

16:                                               ; preds = %11
  %17 = tail call noundef ptr @_ZL9get_by_fdi(i32 noundef %0)
  %.not37 = icmp eq ptr %17, null
  br i1 %.not37, label %21, label %18

18:                                               ; preds = %16
  %19 = load i32, ptr %17, align 8, !tbaa !9
  %20 = and i32 %19, 2048
  %.not38 = icmp eq i32 %20, 0
  br i1 %.not38, label %24, label %21

21:                                               ; preds = %18, %16
  %22 = load ptr, ptr @_ZL17g_sys_sendto_func, align 8, !tbaa !5
  %23 = tail call noundef i64 %22(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5)
  br label %44

24:                                               ; preds = %18
  %25 = load ptr, ptr @_ZL17g_sys_sendto_func, align 8, !tbaa !5
  %26 = tail call noundef i64 %25(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5)
  %27 = icmp slt i64 %26, 0
  br i1 %27, label %28, label %44

28:                                               ; preds = %24
  %29 = tail call ptr @__errno_location() #7
  %30 = load i32, ptr %29, align 4, !tbaa !17
  %31 = icmp eq i32 %30, 11
  br i1 %31, label %32, label %44

32:                                               ; preds = %28
  %33 = getelementptr inbounds i8, ptr %17, i64 40
  %34 = load i64, ptr %33, align 8, !tbaa !18
  %35 = mul nsw i64 %34, 1000
  %36 = getelementptr inbounds i8, ptr %17, i64 48
  %37 = load i64, ptr %36, align 8, !tbaa !19
  %38 = sdiv i64 %37, 1000
  %39 = add nsw i64 %38, %35
  %40 = trunc i64 %39 to i32
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #6
  store i64 120259084288, ptr %7, align 8
  store i32 %0, ptr %7, align 8, !tbaa !20
  %41 = call i32 @poll(ptr noundef nonnull %7, i64 noundef 1, i32 noundef %40)
  %42 = load ptr, ptr @_ZL17g_sys_sendto_func, align 8, !tbaa !5
  %43 = call noundef i64 %42(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #6
  br label %44

44:                                               ; preds = %21, %32, %28, %24, %13
  %.1 = phi i64 [ %15, %13 ], [ %23, %21 ], [ %43, %32 ], [ %26, %28 ], [ %26, %24 ]
  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 = !{!11, !11, i64 0}
!18 = !{!10, !16, i64 40}
!19 = !{!10, !16, i64 48}
!20 = !{!21, !11, i64 0}
!21 = !{!"_ZTS6pollfd", !11, i64 0, !13, i64 4, !13, i64 6}


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