; 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: 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
declare dso_local void @ikcp_flush(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @ikcp_update(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.IKCPCB, ptr %7, i32 0, i32 19
  store i32 %6, ptr %8, align 4, !tbaa !11
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.IKCPCB, ptr %9, i32 0, i32 28
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %21

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.IKCPCB, ptr %14, i32 0, i32 28
  store i32 1, ptr %15, align 8, !tbaa !14
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.IKCPCB, ptr %16, i32 0, i32 19
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.IKCPCB, ptr %19, i32 0, i32 21
  store i32 %18, ptr %20, align 4, !tbaa !15
  br label %21

21:                                               ; preds = %13, %2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.IKCPCB, ptr %22, i32 0, i32 19
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.IKCPCB, ptr %25, i32 0, i32 21
  %27 = load i32, ptr %26, align 4, !tbaa !15
  %28 = call i64 @_itimediff(i32 noundef %24, i32 noundef %27)
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %5, align 4, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp sge i32 %30, 10000
  br i1 %31, label %35, label %32

32:                                               ; preds = %21
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = icmp slt i32 %33, -10000
  br i1 %34, label %35, label %41

35:                                               ; preds = %32, %21
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.IKCPCB, ptr %36, i32 0, i32 19
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.IKCPCB, ptr %39, i32 0, i32 21
  store i32 %38, ptr %40, align 4, !tbaa !15
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %35, %32
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = icmp sge i32 %42, 0
  br i1 %43, label %44, label %72

44:                                               ; preds = %41
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.IKCPCB, ptr %45, i32 0, i32 20
  %47 = load i32, ptr %46, align 8, !tbaa !16
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.IKCPCB, ptr %48, i32 0, i32 21
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %51 = add i32 %50, %47
  store i32 %51, ptr %49, align 4, !tbaa !15
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.IKCPCB, ptr %52, i32 0, i32 19
  %54 = load i32, ptr %53, align 4, !tbaa !11
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.IKCPCB, ptr %55, i32 0, i32 21
  %57 = load i32, ptr %56, align 4, !tbaa !15
  %58 = call i64 @_itimediff(i32 noundef %54, i32 noundef %57)
  %59 = icmp sge i64 %58, 0
  br i1 %59, label %60, label %70

60:                                               ; preds = %44
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.IKCPCB, ptr %61, i32 0, i32 19
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.IKCPCB, ptr %64, i32 0, i32 20
  %66 = load i32, ptr %65, align 8, !tbaa !16
  %67 = add i32 %63, %66
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.IKCPCB, ptr %68, i32 0, i32 21
  store i32 %67, ptr %69, align 4, !tbaa !15
  br label %70

70:                                               ; preds = %60, %44
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ikcp_flush(ptr noundef %71)
  br label %72

72:                                               ; preds = %70, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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 76}
!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, !10, i64 84}
!16 = !{!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
declare dso_local void @ikcp_flush(ptr noundef) local_unnamed_addr #1

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

._crit_edge:                                      ; preds = %2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 84
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !13
  br label %9

7:                                                ; preds = %2
  store i32 1, ptr %4, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 84
  store i32 %1, ptr %8, align 4, !tbaa !13
  br label %9

9:                                                ; preds = %._crit_edge, %7
  %10 = phi i32 [ %.pre, %._crit_edge ], [ %1, %7 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 84
  %12 = tail call i64 @_itimediff(i32 noundef %1, i32 noundef %10)
  %13 = trunc i64 %12 to i32
  %14 = add i32 %13, -10000
  %or.cond = icmp ult i32 %14, -20000
  br i1 %or.cond, label %.thread, label %16

.thread:                                          ; preds = %9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  br label %18

16:                                               ; preds = %9
  %17 = icmp sgt i32 %13, -1
  br i1 %17, label %._crit_edge23, label %31

._crit_edge23:                                    ; preds = %16
  %.pre24 = load i32, ptr %11, align 4, !tbaa !13
  %.pre25 = load i32, ptr %3, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %._crit_edge23, %.thread
  %19 = phi i32 [ %.pre25, %._crit_edge23 ], [ %15, %.thread ]
  %20 = phi i32 [ %.pre24, %._crit_edge23 ], [ %15, %.thread ]
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  %22 = load i32, ptr %21, align 8, !tbaa !14
  %23 = add i32 %20, %22
  store i32 %23, ptr %11, align 4, !tbaa !13
  %24 = tail call i64 @_itimediff(i32 noundef %19, i32 noundef %23)
  %25 = icmp sgt i64 %24, -1
  br i1 %25, label %26, label %30

26:                                               ; preds = %18
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr %21, align 8, !tbaa !14
  %29 = add i32 %28, %27
  store i32 %29, ptr %11, align 4, !tbaa !13
  br label %30

30:                                               ; preds = %26, %18
  tail call void @ikcp_flush(ptr noundef nonnull %0)
  br label %31

31:                                               ; preds = %30, %16
  ret void
}

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

!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 76}
!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 = !{!6, !7, i64 84}
!14 = !{!6, !7, i64 80}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass