; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (TcpComputeRtt)

; 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._TCP_CB = type { %struct._LIST_ENTRY, ptr, ptr, %struct._TCP_PEER, %struct._TCP_PEER, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32, i8, i8, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i32, i32, i32, i32, i32, i16, i16, [6 x i32], i32, i32, i32, i8, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i8, i8, i32, i32, i32, i8, i8, i16, i32, i32, i32, i8, i8, i8, %struct.EFI_IPv4_ADDRESS, ptr }
%struct._TCP_PEER = type { i32, i16 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

@.str.6 = external hidden unnamed_addr constant [72 x i8], align 1

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

declare zeroext i8 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @TcpComputeRtt(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 ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._TCP_CB, ptr %6, i32 0, i32 40
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %41

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._TCP_CB, ptr %11, i32 0, i32 40
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = shl i32 %14, 3
  %16 = sub i32 %13, %15
  store i32 %16, ptr %5, align 4, !tbaa !9
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %10
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = sub nsw i32 0, %20
  store i32 %21, ptr %5, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %19, %10
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._TCP_CB, ptr %23, i32 0, i32 41
  %25 = load i32, ptr %24, align 8, !tbaa !17
  %26 = mul i32 3, %25
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = add i32 %26, %27
  %29 = lshr i32 %28, 2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._TCP_CB, ptr %30, i32 0, i32 41
  store i32 %29, ptr %31, align 8, !tbaa !17
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._TCP_CB, ptr %32, i32 0, i32 40
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = lshr i32 %34, 3
  %36 = mul i32 7, %35
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = add i32 %36, %37
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._TCP_CB, ptr %39, i32 0, i32 40
  store i32 %38, ptr %40, align 4, !tbaa !11
  br label %50

41:                                               ; preds = %2
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = shl i32 %42, 3
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._TCP_CB, ptr %44, i32 0, i32 40
  store i32 %43, ptr %45, align 4, !tbaa !11
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = shl i32 %46, 2
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._TCP_CB, ptr %48, i32 0, i32 41
  store i32 %47, ptr %49, align 8, !tbaa !17
  br label %50

50:                                               ; preds = %41, %22
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._TCP_CB, ptr %51, i32 0, i32 40
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._TCP_CB, ptr %54, i32 0, i32 41
  %56 = load i32, ptr %55, align 8, !tbaa !17
  %57 = mul i32 4, %56
  %58 = icmp ugt i32 8, %57
  br i1 %58, label %59, label %60

59:                                               ; preds = %50
  br label %65

60:                                               ; preds = %50
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._TCP_CB, ptr %61, i32 0, i32 41
  %63 = load i32, ptr %62, align 8, !tbaa !17
  %64 = mul i32 4, %63
  br label %65

65:                                               ; preds = %60, %59
  %66 = phi i32 [ 8, %59 ], [ %64, %60 ]
  %67 = add i32 %53, %66
  %68 = lshr i32 %67, 3
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._TCP_CB, ptr %69, i32 0, i32 42
  store i32 %68, ptr %70, align 4, !tbaa !18
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._TCP_CB, ptr %71, i32 0, i32 42
  %73 = load i32, ptr %72, align 4, !tbaa !18
  %74 = icmp ult i32 %73, 5
  br i1 %74, label %75, label %78

75:                                               ; preds = %65
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._TCP_CB, ptr %76, i32 0, i32 42
  store i32 5, ptr %77, align 4, !tbaa !18
  br label %87

78:                                               ; preds = %65
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._TCP_CB, ptr %79, i32 0, i32 42
  %81 = load i32, ptr %80, align 4, !tbaa !18
  %82 = icmp ugt i32 %81, 300
  br i1 %82, label %83, label %86

83:                                               ; preds = %78
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._TCP_CB, ptr %84, i32 0, i32 42
  store i32 300, ptr %85, align 4, !tbaa !18
  br label %86

86:                                               ; preds = %83, %78
  br label %87

87:                                               ; preds = %86, %75
  br label %88

88:                                               ; preds = %87
  %89 = call zeroext i8 @DebugPrintEnabled()
  %90 = icmp ne i8 %89, 0
  br i1 %90, label %91, label %109

91:                                               ; preds = %88
  br label %92

92:                                               ; preds = %91
  %93 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %94 = icmp ne i8 %93, 0
  br i1 %94, label %95, label %106

95:                                               ; preds = %92
  %96 = load ptr, ptr %3, align 8, !tbaa !5
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct._TCP_CB, ptr %97, i32 0, i32 40
  %99 = load i32, ptr %98, align 4, !tbaa !11
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct._TCP_CB, ptr %100, i32 0, i32 41
  %102 = load i32, ptr %101, align 8, !tbaa !17
  %103 = load ptr, ptr %3, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct._TCP_CB, ptr %103, i32 0, i32 42
  %105 = load i32, ptr %104, align 4, !tbaa !18
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.6, ptr noundef %96, i32 noundef %99, i32 noundef %102, i32 noundef %105)
  br label %106

106:                                              ; preds = %95, %92
  br label %107

107:                                              ; preds = %106
  br label %108

108:                                              ; preds = %107
  br label %109

109:                                              ; preds = %108, %88
  br label %110

110:                                              ; preds = %109
  br label %111

111:                                              ; preds = %110
  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 = { "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 212}
!12 = !{!"_TCP_CB", !13, i64 0, !6, i64 16, !6, i64 24, !14, i64 32, !14, i64 40, !13, i64 48, !13, i64 64, !10, i64 80, !10, i64 84, !7, i64 88, !7, i64 89, !15, i64 90, !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, !15, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !10, i64 148, !15, i64 152, !15, i64 154, !7, i64 156, !10, i64 180, !10, i64 184, !10, i64 188, !7, i64 192, !7, i64 193, !7, i64 194, !10, i64 196, !10, i64 200, !10, i64 204, !10, i64 208, !10, i64 212, !10, i64 216, !10, i64 220, !10, i64 224, !10, i64 228, !10, i64 232, !15, i64 236, !7, i64 238, !7, i64 239, !10, i64 240, !10, i64 244, !10, i64 248, !7, i64 252, !7, i64 253, !15, i64 254, !10, i64 256, !10, i64 260, !10, i64 264, !7, i64 268, !7, i64 269, !7, i64 270, !16, i64 271, !6, i64 280}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!"_TCP_PEER", !10, i64 0, !15, i64 4}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !7, i64 0}
!17 = !{!12, !10, i64 216}
!18 = !{!12, !10, i64 220}


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

@.str.6 = external hidden unnamed_addr constant [72 x i8], align 1

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #0

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #0

declare void @DebugPrint(i64 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TcpComputeRtt(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 212
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  %5 = shl i32 %1, 3
  %6 = getelementptr inbounds i8, ptr %0, i64 216
  br i1 %.not, label %16, label %7

7:                                                ; preds = %2
  %8 = sub i32 %4, %5
  %spec.select = tail call i32 @llvm.abs.i32(i32 %8, i1 true)
  %9 = load i32, ptr %6, align 8, !tbaa !15
  %10 = mul i32 %9, 3
  %11 = add i32 %10, %spec.select
  %12 = lshr i32 %11, 2
  store i32 %12, ptr %6, align 8, !tbaa !15
  %13 = lshr i32 %4, 3
  %14 = mul nuw i32 %13, 7
  %15 = add i32 %14, %1
  store i32 %15, ptr %3, align 4, !tbaa !5
  br label %18

16:                                               ; preds = %2
  store i32 %5, ptr %3, align 4, !tbaa !5
  %17 = shl i32 %1, 2
  store i32 %17, ptr %6, align 8, !tbaa !15
  br label %18

18:                                               ; preds = %16, %7
  %19 = phi i32 [ %17, %16 ], [ %12, %7 ]
  %20 = phi i32 [ %5, %16 ], [ %15, %7 ]
  %21 = getelementptr inbounds i8, ptr %0, i64 216
  %22 = shl i32 %19, 2
  %spec.select32 = tail call i32 @llvm.umax.i32(i32 %22, i32 8)
  %23 = add i32 %spec.select32, %20
  %24 = lshr i32 %23, 3
  %25 = getelementptr inbounds i8, ptr %0, i64 220
  store i32 %24, ptr %25, align 4, !tbaa !16
  %26 = icmp ult i32 %23, 40
  br i1 %26, label %.sink.split, label %27

27:                                               ; preds = %18
  %28 = icmp ugt i32 %23, 2407
  br i1 %28, label %.sink.split, label %29

.sink.split:                                      ; preds = %27, %18
  %.sink = phi i32 [ 5, %18 ], [ 300, %27 ]
  store i32 %.sink, ptr %25, align 4, !tbaa !16
  br label %29

29:                                               ; preds = %.sink.split, %27
  %30 = tail call zeroext i8 @DebugPrintEnabled() #3
  %.not30 = icmp eq i8 %30, 0
  br i1 %.not30, label %37, label %31

31:                                               ; preds = %29
  %32 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #3
  %.not31 = icmp eq i8 %32, 0
  br i1 %.not31, label %37, label %33

33:                                               ; preds = %31
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = load i32, ptr %21, align 8, !tbaa !15
  %36 = load i32, ptr %25, align 4, !tbaa !16
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.6, ptr noundef nonnull %0, i32 noundef %34, i32 noundef %35, i32 noundef %36) #3
  br label %37

37:                                               ; preds = %31, %33, %29
  ret void
}

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

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

attributes #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) }
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, !12, i64 212}
!6 = !{!"_TCP_CB", !7, i64 0, !8, i64 16, !8, i64 24, !11, i64 32, !11, i64 40, !7, i64 48, !7, i64 64, !12, i64 80, !12, i64 84, !9, i64 88, !9, i64 89, !13, i64 90, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !13, i64 128, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !12, i64 148, !13, i64 152, !13, i64 154, !9, i64 156, !12, i64 180, !12, i64 184, !12, i64 188, !9, i64 192, !9, i64 193, !9, i64 194, !12, i64 196, !12, i64 200, !12, i64 204, !12, i64 208, !12, i64 212, !12, i64 216, !12, i64 220, !12, i64 224, !12, i64 228, !12, i64 232, !13, i64 236, !9, i64 238, !9, i64 239, !12, i64 240, !12, i64 244, !12, i64 248, !9, i64 252, !9, i64 253, !13, i64 254, !12, i64 256, !12, i64 260, !12, i64 264, !9, i64 268, !9, i64 269, !9, i64 270, !14, i64 271, !8, i64 280}
!7 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"_TCP_PEER", !12, i64 0, !13, i64 4}
!12 = !{!"int", !9, i64 0}
!13 = !{!"short", !9, i64 0}
!14 = !{!"", !9, i64 0}
!15 = !{!6, !12, i64 216}
!16 = !{!6, !12, i64 220}


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