; LLVM IR from shixiongfei/nio4c :: nio4c_socket (nio_socketreadable)

; 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.timeval = type { i64, i64 }
%struct.fd_set = type { [16 x i64] }
%struct.niosocket_s = type { i32 }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @nio_socketreadable(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %struct.timeval, align 8
  %7 = alloca %struct.fd_set, align 8
  %8 = alloca %struct.fd_set, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 8 %6, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 128, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 128, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  br label %15

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr %7, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %26, %15
  %17 = load i32, ptr %10, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = icmp ult i64 %18, 16
  br i1 %19, label %20, label %29

20:                                               ; preds = %16
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.fd_set, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [16 x i64], ptr %22, i64 0, i64 %24
  store i64 0, ptr %25, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %20
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = add i32 %27, 1
  store i32 %28, ptr %10, align 4, !tbaa !9
  br label %16, !llvm.loop !13

29:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store ptr %8, ptr %13, align 8, !tbaa !5
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %43, %32
  %34 = load i32, ptr %12, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = icmp ult i64 %35, 16
  br i1 %36, label %37, label %46

37:                                               ; preds = %33
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.fd_set, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds [16 x i64], ptr %39, i64 0, i64 %41
  store i64 0, ptr %42, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %37
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = add i32 %44, 1
  store i32 %45, ptr %12, align 4, !tbaa !9
  br label %33, !llvm.loop !15

46:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.niosocket_s, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !16
  %52 = srem i32 %51, 64
  %53 = zext i32 %52 to i64
  %54 = shl i64 1, %53
  %55 = getelementptr inbounds %struct.fd_set, ptr %7, i32 0, i32 0
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.niosocket_s, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 4, !tbaa !16
  %59 = sdiv i32 %58, 64
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [16 x i64], ptr %55, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !11
  %63 = or i64 %62, %54
  store i64 %63, ptr %61, align 8, !tbaa !11
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.niosocket_s, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 4, !tbaa !16
  %67 = srem i32 %66, 64
  %68 = zext i32 %67 to i64
  %69 = shl i64 1, %68
  %70 = getelementptr inbounds %struct.fd_set, ptr %8, i32 0, i32 0
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.niosocket_s, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 4, !tbaa !16
  %74 = sdiv i32 %73, 64
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [16 x i64], ptr %70, i64 0, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !11
  %78 = or i64 %77, %69
  store i64 %78, ptr %76, align 8, !tbaa !11
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = icmp ugt i32 %79, 0
  br i1 %80, label %81, label %92

81:                                               ; preds = %48
  %82 = load i32, ptr %5, align 4, !tbaa !9
  %83 = uitofp i32 %82 to double
  %84 = fmul double %83, 1.000000e-03
  %85 = fptosi double %84 to i64
  %86 = getelementptr inbounds %struct.timeval, ptr %6, i32 0, i32 0
  store i64 %85, ptr %86, align 8, !tbaa !18
  %87 = load i32, ptr %5, align 4, !tbaa !9
  %88 = urem i32 %87, 1000
  %89 = mul i32 %88, 1000
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds %struct.timeval, ptr %6, i32 0, i32 1
  store i64 %90, ptr %91, align 8, !tbaa !20
  br label %92

92:                                               ; preds = %81, %48
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.niosocket_s, ptr %93, i32 0, i32 0
  %95 = load i32, ptr %94, align 4, !tbaa !16
  %96 = add nsw i32 %95, 1
  %97 = call i32 @select(i32 noundef %96, ptr noundef %7, ptr noundef null, ptr noundef %8, ptr noundef %6)
  store i32 %97, ptr %9, align 4, !tbaa !9
  %98 = load i32, ptr %9, align 4, !tbaa !9
  %99 = icmp slt i32 %98, 0
  br i1 %99, label %100, label %101

100:                                              ; preds = %92
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %14, align 4
  br label %142

101:                                              ; preds = %92
  %102 = load i32, ptr %9, align 4, !tbaa !9
  %103 = icmp sgt i32 %102, 0
  br i1 %103, label %104, label %141

104:                                              ; preds = %101
  %105 = getelementptr inbounds %struct.fd_set, ptr %8, i32 0, i32 0
  %106 = load ptr, ptr %4, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.niosocket_s, ptr %106, i32 0, i32 0
  %108 = load i32, ptr %107, align 4, !tbaa !16
  %109 = sdiv i32 %108, 64
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [16 x i64], ptr %105, i64 0, i64 %110
  %112 = load i64, ptr %111, align 8, !tbaa !11
  %113 = load ptr, ptr %4, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.niosocket_s, ptr %113, i32 0, i32 0
  %115 = load i32, ptr %114, align 4, !tbaa !16
  %116 = srem i32 %115, 64
  %117 = zext i32 %116 to i64
  %118 = shl i64 1, %117
  %119 = and i64 %112, %118
  %120 = icmp ne i64 %119, 0
  br i1 %120, label %121, label %122

121:                                              ; preds = %104
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %14, align 4
  br label %142

122:                                              ; preds = %104
  %123 = getelementptr inbounds %struct.fd_set, ptr %7, i32 0, i32 0
  %124 = load ptr, ptr %4, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.niosocket_s, ptr %124, i32 0, i32 0
  %126 = load i32, ptr %125, align 4, !tbaa !16
  %127 = sdiv i32 %126, 64
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds [16 x i64], ptr %123, i64 0, i64 %128
  %130 = load i64, ptr %129, align 8, !tbaa !11
  %131 = load ptr, ptr %4, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.niosocket_s, ptr %131, i32 0, i32 0
  %133 = load i32, ptr %132, align 4, !tbaa !16
  %134 = srem i32 %133, 64
  %135 = zext i32 %134 to i64
  %136 = shl i64 1, %135
  %137 = and i64 %130, %136
  %138 = icmp ne i64 %137, 0
  br i1 %138, label %139, label %140

139:                                              ; preds = %122
  store i32 1, ptr %3, align 4
  store i32 1, ptr %14, align 4
  br label %142

140:                                              ; preds = %122
  br label %141

141:                                              ; preds = %140, %101
  store i32 0, ptr %3, align 4
  store i32 1, ptr %14, align 4
  br label %142

142:                                              ; preds = %141, %139, %121, %100
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  %143 = load i32, ptr %3, align 4
  ret i32 %143
}

declare i32 @select(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { "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 }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !10, i64 0}
!17 = !{!"niosocket_s", !10, i64 0}
!18 = !{!19, !12, i64 0}
!19 = !{!"timeval", !12, i64 0, !12, i64 8}
!20 = !{!19, !12, i64 8}


; 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.timeval = type { i64, i64 }
%struct.fd_set = type { [16 x i64] }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @nio_socketreadable(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #2 {
.preheader.preheader:
  %2 = alloca %struct.timeval, align 8
  %3 = alloca %struct.fd_set, align 8
  %4 = alloca %struct.fd_set, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %3, i8 0, i64 128, i1 false), !tbaa !5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %4, i8 0, i64 128, i1 false), !tbaa !5
  %5 = load i32, ptr %0, align 4, !tbaa !9
  %6 = srem i32 %5, 64
  %7 = zext nneg i32 %6 to i64
  %8 = shl nuw i64 1, %7
  %9 = sdiv i32 %5, 64
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [16 x i64], ptr %3, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = or i64 %8, %12
  store i64 %13, ptr %11, align 8, !tbaa !5
  %14 = getelementptr inbounds [16 x i64], ptr %4, i64 0, i64 %10
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = or i64 %15, %8
  store i64 %16, ptr %14, align 8, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %25, label %17

17:                                               ; preds = %.preheader.preheader
  %18 = uitofp i32 %1 to double
  %19 = fmul double %18, 1.000000e-03
  %20 = fptosi double %19 to i64
  store i64 %20, ptr %2, align 8, !tbaa !12
  %21 = urem i32 %1, 1000
  %22 = mul nuw nsw i32 %21, 1000
  %23 = zext nneg i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %2, i64 8
  store i64 %23, ptr %24, align 8, !tbaa !14
  br label %25

25:                                               ; preds = %17, %.preheader.preheader
  %26 = add nsw i32 %5, 1
  %27 = call i32 @select(i32 noundef %26, ptr noundef nonnull %3, ptr noundef null, ptr noundef nonnull %4, ptr noundef nonnull %2) #4
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %45, label %29

29:                                               ; preds = %25
  %.not28 = icmp eq i32 %27, 0
  br i1 %.not28, label %44, label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %0, align 4, !tbaa !9
  %32 = sdiv i32 %31, 64
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [16 x i64], ptr %4, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = srem i32 %31, 64
  %37 = zext nneg i32 %36 to i64
  %38 = shl nuw i64 1, %37
  %39 = and i64 %38, %35
  %.not29 = icmp eq i64 %39, 0
  br i1 %.not29, label %40, label %45

40:                                               ; preds = %30
  %41 = getelementptr inbounds [16 x i64], ptr %3, i64 0, i64 %33
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = and i64 %42, %38
  %.not30 = icmp eq i64 %43, 0
  br i1 %.not30, label %44, label %45

44:                                               ; preds = %40, %29
  br label %45

45:                                               ; preds = %40, %30, %25, %44
  %.0 = phi i32 [ 0, %44 ], [ -1, %25 ], [ -1, %30 ], [ 1, %40 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  ret i32 %.0
}

declare i32 @select(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { "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 }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"niosocket_s", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"timeval", !6, i64 0, !6, i64 8}
!14 = !{!13, !6, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass