; 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_read_func = external hidden global ptr, align 8
@.str.6 = 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

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

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

19:                                               ; preds = %17, %3
  %20 = call noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
  br i1 %20, label %27, label %21

21:                                               ; preds = %19
  %22 = load ptr, ptr @_ZL15g_sys_read_func, align 8, !tbaa !9
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = load i64, ptr %7, align 8, !tbaa !11
  %26 = call noundef i64 %22(i32 noundef %23, ptr noundef %24, i64 noundef %25)
  store i64 %26, ptr %4, align 8
  br label %80

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

32:                                               ; preds = %27
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.rpchook_t, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = and i32 2048, %35
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %45

38:                                               ; preds = %32, %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %39 = load ptr, ptr @_ZL15g_sys_read_func, align 8, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = load i64, ptr %7, align 8, !tbaa !11
  %43 = call noundef i64 %39(i32 noundef %40, ptr noundef %41, i64 noundef %42)
  store i64 %43, ptr %9, align 8, !tbaa !11
  %44 = load i64, ptr %9, align 8, !tbaa !11
  store i64 %44, ptr %4, align 8
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  br label %79

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

70:                                               ; preds = %45
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = load i64, ptr %14, align 8, !tbaa !11
  %73 = call ptr @__errno_location() #8
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = load i32, ptr %13, align 4, !tbaa !5
  %76 = load i32, ptr %11, align 4, !tbaa !5
  call void (ptr, ...) @_Z10co_log_errPKcz(ptr noundef @.str.35, i32 noundef %71, i64 noundef %72, i32 noundef %74, i32 noundef %75, i32 noundef %76)
  br label %77

77:                                               ; preds = %70, %45
  %78 = load i64, ptr %14, align 8, !tbaa !11
  store i64 %78, ptr %4, align 8
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  br label %79

79:                                               ; preds = %77, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  br label %80

80:                                               ; preds = %79, %21
  %81 = load i64, ptr %4, align 8
  ret i64 %81
}

declare void @_Z10co_log_errPKcz(ptr noundef, ...) #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 = { 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_read_func = external hidden local_unnamed_addr global ptr, align 8
@.str.6 = 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

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

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

8:                                                ; preds = %6, %3
  %9 = tail call noundef zeroext i1 @_Z21co_is_enable_sys_hookv()
  br i1 %9, label %13, label %10

10:                                               ; preds = %8
  %11 = load ptr, ptr @_ZL15g_sys_read_func, align 8, !tbaa !5
  %12 = tail call noundef i64 %11(i32 noundef %0, ptr noundef %1, i64 noundef %2)
  br label %38

13:                                               ; preds = %8
  %14 = tail call noundef ptr @_ZL9get_by_fdi(i32 noundef %0)
  %.not25 = icmp eq ptr %14, null
  br i1 %.not25, label %18, label %15

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

18:                                               ; preds = %15, %13
  %19 = load ptr, ptr @_ZL15g_sys_read_func, align 8, !tbaa !5
  %20 = tail call noundef i64 %19(i32 noundef %0, ptr noundef %1, i64 noundef %2)
  br label %38

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

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

37:                                               ; preds = %34, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br label %38

38:                                               ; preds = %18, %37, %10
  %.1 = phi i64 [ %12, %10 ], [ %20, %18 ], [ %32, %37 ]
  ret i64 %.1
}

declare void @_Z10co_log_errPKcz(ptr noundef, ...) local_unnamed_addr #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