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

; Function Attrs: nounwind uwtable
define dso_local i32 @ikcp_nodelay(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp sge i32 %11, 0
  br i1 %12, label %13, label %26

13:                                               ; preds = %5
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.IKCPCB, ptr %15, i32 0, i32 27
  store i32 %14, ptr %16, align 4, !tbaa !11
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %13
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.IKCPCB, ptr %20, i32 0, i32 13
  store i32 30, ptr %21, align 4, !tbaa !14
  br label %25

22:                                               ; preds = %13
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.IKCPCB, ptr %23, i32 0, i32 13
  store i32 100, ptr %24, align 4, !tbaa !14
  br label %25

25:                                               ; preds = %22, %19
  br label %26

26:                                               ; preds = %25, %5
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %29, label %42

29:                                               ; preds = %26
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp sgt i32 %30, 5000
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i32 5000, ptr %8, align 4, !tbaa !9
  br label %38

33:                                               ; preds = %29
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 10
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i32 10, ptr %8, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %36, %33
  br label %38

38:                                               ; preds = %37, %32
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.IKCPCB, ptr %40, i32 0, i32 20
  store i32 %39, ptr %41, align 8, !tbaa !15
  br label %42

42:                                               ; preds = %38, %26
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = icmp sge i32 %43, 0
  br i1 %44, label %45, label %49

45:                                               ; preds = %42
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.IKCPCB, ptr %47, i32 0, i32 42
  store i32 %46, ptr %48, align 8, !tbaa !16
  br label %49

49:                                               ; preds = %45, %42
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = icmp sge i32 %50, 0
  br i1 %51, label %52, label %56

52:                                               ; preds = %49
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.IKCPCB, ptr %54, i32 0, i32 44
  store i32 %53, ptr %55, align 8, !tbaa !17
  br label %56

56:                                               ; preds = %52, %49
  ret i32 0
}

attributes #0 = { 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" }

!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 108}
!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 52}
!15 = !{!12, !10, i64 80}
!16 = !{!12, !10, i64 232}
!17 = !{!12, !10, i64 240}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local noundef i32 @ikcp_nodelay(ptr nocapture noundef writeonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp sgt i32 %1, -1
  br i1 %6, label %.sink.split, label %9

.sink.split:                                      ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 108
  store i32 %1, ptr %7, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  %8 = getelementptr inbounds i8, ptr %0, i64 52
  %. = select i1 %.not, i32 100, i32 30
  store i32 %., ptr %8, align 4, !tbaa !12
  br label %9

9:                                                ; preds = %.sink.split, %5
  %10 = icmp sgt i32 %2, -1
  br i1 %10, label %11, label %14

11:                                               ; preds = %9
  %12 = tail call i32 @llvm.umax.i32(i32 %2, i32 10)
  %.0 = tail call i32 @llvm.umin.i32(i32 %12, i32 5000)
  %13 = getelementptr inbounds i8, ptr %0, i64 80
  store i32 %.0, ptr %13, align 8, !tbaa !13
  br label %14

14:                                               ; preds = %11, %9
  %15 = icmp sgt i32 %3, -1
  br i1 %15, label %16, label %18

16:                                               ; preds = %14
  %17 = getelementptr inbounds i8, ptr %0, i64 232
  store i32 %3, ptr %17, align 8, !tbaa !14
  br label %18

18:                                               ; preds = %16, %14
  %19 = icmp sgt i32 %4, -1
  br i1 %19, label %20, label %22

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %0, i64 240
  store i32 %4, ptr %21, align 8, !tbaa !15
  br label %22

22:                                               ; preds = %20, %18
  ret i32 0
}

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

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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 = { 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 108}
!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 52}
!13 = !{!6, !7, i64 80}
!14 = !{!6, !7, i64 232}
!15 = !{!6, !7, i64 240}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass