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

@_ZL19g_sys_recvfrom_func = external hidden global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [9 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

; Function Attrs: mustprogress uwtable
define dso_local i64 @recvfrom(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #5 {
  %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 ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca %struct.pollfd, align 4
  %18 = alloca i64, align 8
  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 ptr %5, ptr %13, align 8, !tbaa !9
  %19 = load ptr, ptr @_ZL19g_sys_recvfrom_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.12) #6
  store ptr %22, ptr @_ZL19g_sys_recvfrom_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 @_ZL19g_sys_recvfrom_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 ptr, ptr %13, align 8, !tbaa !9
  %33 = call noundef i64 %26(i32 noundef %27, ptr noundef %28, i64 noundef %29, i32 noundef %30, ptr noundef %31, ptr noundef %32)
  store i64 %33, ptr %7, align 8
  br label %82

34:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %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 @_ZL19g_sys_recvfrom_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 ptr, ptr %13, align 8, !tbaa !9
  %53 = call noundef i64 %46(i32 noundef %47, ptr noundef %48, i64 noundef %49, i32 noundef %50, ptr noundef %51, ptr noundef %52)
  store i64 %53, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %81

54:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %55 = load ptr, ptr %14, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.rpchook_t, ptr %55, i32 0, i32 3
  %57 = getelementptr inbounds %struct.timeval, ptr %56, i32 0, i32 0
  %58 = load i64, ptr %57, align 8, !tbaa !19
  %59 = mul nsw i64 %58, 1000
  %60 = load ptr, ptr %14, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.rpchook_t, ptr %60, i32 0, i32 3
  %62 = getelementptr inbounds %struct.timeval, ptr %61, i32 0, i32 1
  %63 = load i64, ptr %62, align 8, !tbaa !20
  %64 = sdiv i64 %63, 1000
  %65 = add nsw i64 %59, %64
  %66 = trunc i64 %65 to i32
  store i32 %66, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  call void @llvm.memset.p0.i64(ptr align 4 %17, i8 0, i64 8, i1 false)
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = getelementptr inbounds %struct.pollfd, ptr %17, i32 0, i32 0
  store i32 %67, ptr %68, align 4, !tbaa !21
  %69 = getelementptr inbounds %struct.pollfd, ptr %17, i32 0, i32 1
  store i16 25, ptr %69, align 4, !tbaa !23
  %70 = load i32, ptr %16, align 4, !tbaa !5
  %71 = call i32 @poll(ptr noundef %17, i64 noundef 1, i32 noundef %70)
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %72 = load ptr, ptr @_ZL19g_sys_recvfrom_func, align 8, !tbaa !9
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = load ptr, ptr %9, align 8, !tbaa !9
  %75 = load i64, ptr %10, align 8, !tbaa !11
  %76 = load i32, ptr %11, align 4, !tbaa !5
  %77 = load ptr, ptr %12, align 8, !tbaa !9
  %78 = load ptr, ptr %13, align 8, !tbaa !9
  %79 = call noundef i64 %72(i32 noundef %73, ptr noundef %74, i64 noundef %75, i32 noundef %76, ptr noundef %77, ptr noundef %78)
  store i64 %79, ptr %18, align 8, !tbaa !11
  %80 = load i64, ptr %18, align 8, !tbaa !11
  store i64 %80, ptr %7, align 8
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  br label %81

81:                                               ; preds = %54, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %82

82:                                               ; preds = %81, %25
  %83 = load i64, ptr %7, align 8
  ret i64 %83
}

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

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

@_ZL19g_sys_recvfrom_func = external hidden local_unnamed_addr global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [9 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 uwtable
declare dso_local i32 @poll(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @recvfrom(i32 noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #4 {
  %7 = alloca %struct.pollfd, align 8
  %8 = load ptr, ptr @_ZL19g_sys_recvfrom_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.12) #5
  store ptr %10, ptr @_ZL19g_sys_recvfrom_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 @_ZL19g_sys_recvfrom_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, ptr noundef %5)
  br label %36

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

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

21:                                               ; preds = %18, %16
  %22 = load ptr, ptr @_ZL19g_sys_recvfrom_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, ptr noundef %5)
  br label %36

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

36:                                               ; preds = %21, %24, %13
  %.1 = phi i64 [ %15, %13 ], [ %23, %21 ], [ %35, %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 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 = { 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, !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}


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