; LLVM IR from wichue/nethello :: depend/kcp (ikcp)

; 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.IKCPCB = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.IQUEUEHEAD, %struct.IQUEUEHEAD, %struct.IQUEUEHEAD, %struct.IQUEUEHEAD, ptr, i32, i32, ptr, ptr, i32, i32, i32, i32, i32, ptr, ptr }
%struct.IQUEUEHEAD = type { ptr, ptr }
%struct.IKCPSEG = type { %struct.IQUEUEHEAD, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [1 x i8] }

; 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: alwaysinline nounwind uwtable
declare hidden i64 @_itimediff(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ikcp_check(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = 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 4, ptr %6) #3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.IKCPCB, ptr %14, i32 0, i32 21
  %16 = load i32, ptr %15, align 4, !tbaa !11
  store i32 %16, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 2147483647, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 2147483647, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.IKCPCB, ptr %17, i32 0, i32 28
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %2
  %22 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %22, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %106

23:                                               ; preds = %2
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = call i64 @_itimediff(i32 noundef %24, i32 noundef %25)
  %27 = icmp sge i64 %26, 10000
  br i1 %27, label %33, label %28

28:                                               ; preds = %23
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = call i64 @_itimediff(i32 noundef %29, i32 noundef %30)
  %32 = icmp slt i64 %31, -10000
  br i1 %32, label %33, label %35

33:                                               ; preds = %28, %23
  %34 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %34, ptr %6, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %33, %28
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = call i64 @_itimediff(i32 noundef %36, i32 noundef %37)
  %39 = icmp sge i64 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %35
  %41 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %41, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %106

42:                                               ; preds = %35
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = call i64 @_itimediff(i32 noundef %43, i32 noundef %44)
  %46 = trunc i64 %45 to i32
  store i32 %46, ptr %7, align 4, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.IKCPCB, ptr %47, i32 0, i32 35
  %49 = getelementptr inbounds %struct.IQUEUEHEAD, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  store ptr %50, ptr %10, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %79, %42
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.IKCPCB, ptr %53, i32 0, i32 35
  %55 = icmp ne ptr %52, %54
  br i1 %55, label %56, label %83

56:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 0
  store ptr %58, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.IKCPSEG, ptr %59, i32 0, i32 9
  %61 = load i32, ptr %60, align 8, !tbaa !16
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = call i64 @_itimediff(i32 noundef %61, i32 noundef %62)
  %64 = trunc i64 %63 to i32
  store i32 %64, ptr %13, align 4, !tbaa !9
  %65 = load i32, ptr %13, align 4, !tbaa !9
  %66 = icmp sle i32 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %56
  %68 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %68, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %76

69:                                               ; preds = %56
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = icmp slt i32 %70, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %69
  %74 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %74, ptr %8, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %73, %69
  store i32 0, ptr %11, align 4
  br label %76

76:                                               ; preds = %75, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %77 = load i32, ptr %11, align 4
  switch i32 %77, label %106 [
    i32 0, label %78
  ]

78:                                               ; preds = %76
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.IQUEUEHEAD, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !18
  store ptr %82, ptr %10, align 8, !tbaa !5
  br label %51, !llvm.loop !19

83:                                               ; preds = %51
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = load i32, ptr %7, align 4, !tbaa !9
  %86 = icmp slt i32 %84, %85
  br i1 %86, label %87, label %89

87:                                               ; preds = %83
  %88 = load i32, ptr %8, align 4, !tbaa !9
  br label %91

89:                                               ; preds = %83
  %90 = load i32, ptr %7, align 4, !tbaa !9
  br label %91

91:                                               ; preds = %89, %87
  %92 = phi i32 [ %88, %87 ], [ %90, %89 ]
  store i32 %92, ptr %9, align 4, !tbaa !9
  %93 = load i32, ptr %9, align 4, !tbaa !9
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.IKCPCB, ptr %94, i32 0, i32 20
  %96 = load i32, ptr %95, align 8, !tbaa !21
  %97 = icmp uge i32 %93, %96
  br i1 %97, label %98, label %102

98:                                               ; preds = %91
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.IKCPCB, ptr %99, i32 0, i32 20
  %101 = load i32, ptr %100, align 8, !tbaa !21
  store i32 %101, ptr %9, align 4, !tbaa !9
  br label %102

102:                                              ; preds = %98, %91
  %103 = load i32, ptr %5, align 4, !tbaa !9
  %104 = load i32, ptr %9, align 4, !tbaa !9
  %105 = add i32 %103, %104
  store i32 %105, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %106

106:                                              ; preds = %102, %76, %40, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %107 = load i32, ptr %3, align 4
  ret i32 %107
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 #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 = { 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, !10, i64 84}
!12 = !{!"IKCPCB", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !13, i64 136, !13, i64 152, !13, i64 168, !13, i64 184, !6, i64 200, !10, i64 208, !10, i64 212, !6, i64 216, !6, i64 224, !10, i64 232, !10, i64 236, !10, i64 240, !10, i64 244, !10, i64 248, !6, i64 256, !6, i64 264}
!13 = !{!"IQUEUEHEAD", !6, i64 0, !6, i64 8}
!14 = !{!12, !10, i64 112}
!15 = !{!12, !6, i64 168}
!16 = !{!17, !10, i64 48}
!17 = !{!"IKCPSEG", !13, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !7, i64 64}
!18 = !{!13, !6, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !10, i64 80}


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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @_itimediff(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ikcp_check(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 84
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 112
  %6 = load i32, ptr %5, align 8, !tbaa !12
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %2
  %9 = tail call i64 @_itimediff(i32 noundef %1, i32 noundef %4)
  %10 = icmp sgt i64 %9, 9999
  br i1 %10, label %14, label %11

11:                                               ; preds = %8
  %12 = tail call i64 @_itimediff(i32 noundef %1, i32 noundef %4)
  %13 = icmp slt i64 %12, -10000
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %8
  br label %15

15:                                               ; preds = %14, %11
  %.035 = phi i32 [ %1, %14 ], [ %4, %11 ]
  %16 = tail call i64 @_itimediff(i32 noundef %1, i32 noundef %.035)
  %17 = icmp sgt i64 %16, -1
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %15
  %19 = tail call i64 @_itimediff(i32 noundef %.035, i32 noundef %1)
  %20 = trunc i64 %19 to i32
  %21 = getelementptr inbounds i8, ptr %0, i64 168
  br label %22

22:                                               ; preds = %23, %18
  %.039 = phi i32 [ 2147483647, %18 ], [ %spec.select, %23 ]
  %.037.in = phi ptr [ %21, %18 ], [ %.037, %23 ]
  %.037 = load ptr, ptr %.037.in, align 8, !tbaa !13
  %.not = icmp eq ptr %.037, %21
  br i1 %.not, label %29, label %23

23:                                               ; preds = %22
  %24 = getelementptr inbounds i8, ptr %.037, i64 48
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = tail call i64 @_itimediff(i32 noundef %25, i32 noundef %1)
  %27 = trunc i64 %26 to i32
  %28 = icmp sgt i32 %27, 0
  %spec.select = tail call i32 @llvm.smin.i32(i32 %.039, i32 %27)
  br i1 %28, label %22, label %.loopexit, !llvm.loop !16

29:                                               ; preds = %22
  %30 = tail call i32 @llvm.smin.i32(i32 %.039, i32 %20)
  %31 = getelementptr inbounds i8, ptr %0, i64 80
  %32 = load i32, ptr %31, align 8, !tbaa !18
  %spec.select46 = tail call i32 @llvm.umin.i32(i32 %30, i32 %32)
  %33 = add i32 %spec.select46, %1
  br label %.loopexit

.loopexit:                                        ; preds = %23, %15, %2, %29
  %.2 = phi i32 [ %33, %29 ], [ %1, %2 ], [ %1, %15 ], [ %1, %23 ]
  ret i32 %.2
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

attributes #0 = { alwaysinline 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable 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, !7, i64 84}
!6 = !{!"IKCPCB", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !7, i64 128, !10, i64 136, !10, i64 152, !10, i64 168, !10, i64 184, !11, i64 200, !7, i64 208, !7, i64 212, !11, i64 216, !11, i64 224, !7, i64 232, !7, i64 236, !7, i64 240, !7, i64 244, !7, i64 248, !11, i64 256, !11, i64 264}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"IQUEUEHEAD", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 112}
!13 = !{!10, !11, i64 0}
!14 = !{!15, !7, i64 48}
!15 = !{!"IKCPSEG", !10, i64 0, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !8, i64 64}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !7, i64 80}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass