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

; 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.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct._EFI_TCP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@gBS = external global ptr, align 8

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

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %68

15:                                               ; preds = %11
  store ptr null, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr @gBS, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %16, i32 0, i32 8
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call i64 %18(i32 noundef -2147483648, i64 noundef 8, ptr noundef null, ptr noundef null, ptr noundef %7)
  store i64 %19, ptr %6, align 8, !tbaa !14
  %20 = load i64, ptr %6, align 8, !tbaa !14
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %15
  br label %57

23:                                               ; preds = %15
  %24 = load ptr, ptr @gBS, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %24, i32 0, i32 9
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i64 %26(ptr noundef %27, i32 noundef 2, i64 noundef 100000000)
  store i64 %28, ptr %6, align 8, !tbaa !14
  %29 = load i64, ptr %6, align 8, !tbaa !14
  %30 = icmp slt i64 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %23
  br label %57

32:                                               ; preds = %23
  br label %33

33:                                               ; preds = %55, %32
  %34 = load ptr, ptr @gBS, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %34, i32 0, i32 13
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = call i64 %36(ptr noundef %37)
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %40, label %56

40:                                               ; preds = %33
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._EFI_TCP6_PROTOCOL, ptr %41, i32 0, i32 8
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = call i64 %43(ptr noundef %44)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._EFI_TCP6_PROTOCOL, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = call i64 %48(ptr noundef %49, ptr noundef %50)
  store i64 %51, ptr %6, align 8, !tbaa !14
  %52 = load i64, ptr %6, align 8, !tbaa !14
  %53 = icmp slt i64 %52, 0
  br i1 %53, label %55, label %54

54:                                               ; preds = %40
  br label %56

55:                                               ; preds = %40
  br label %33, !llvm.loop !20

56:                                               ; preds = %54, %33
  br label %57

57:                                               ; preds = %56, %31, %22
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %66

60:                                               ; preds = %57
  %61 = load ptr, ptr @gBS, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %61, i32 0, i32 12
  %63 = load ptr, ptr %62, align 8, !tbaa !22
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = call i64 %63(ptr noundef %64)
  br label %66

66:                                               ; preds = %60, %57
  %67 = load i64, ptr %6, align 8, !tbaa !14
  store i64 %67, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %68

68:                                               ; preds = %66, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %69 = load i64, ptr %3, align 8
  ret i64 %69
}

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

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !6, i64 80}
!10 = !{!"", !11, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !6, i64 88}
!16 = !{!10, !6, i64 120}
!17 = !{!18, !6, i64 64}
!18 = !{!"_EFI_TCP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!19 = !{!18, !6, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !6, i64 112}


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

@gBS = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @TcpIoGetMapping(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %1, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %46, label %6

6:                                                ; preds = %2
  store ptr null, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr @gBS, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 80
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = call i64 %9(i32 noundef -2147483648, i64 noundef 8, ptr noundef null, ptr noundef null, ptr noundef nonnull %3) #2
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %6
  %13 = load ptr, ptr @gBS, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 88
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i64 %15(ptr noundef %16, i32 noundef 2, i64 noundef 100000000) #2
  %18 = icmp slt i64 %17, 0
  br i1 %18, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %12
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  %20 = load ptr, ptr @gBS, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 120
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call i64 %22(ptr noundef %23) #2
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  br label %34

27:                                               ; preds = %34
  %28 = load ptr, ptr @gBS, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 120
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = call i64 %30(ptr noundef %31) #2
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %34, label %.loopexit, !llvm.loop !16

34:                                               ; preds = %.lr.ph, %27
  %35 = load ptr, ptr %19, align 8, !tbaa !18
  %36 = call i64 %35(ptr noundef nonnull %0) #2
  %37 = load ptr, ptr %26, align 8, !tbaa !20
  %38 = call i64 %37(ptr noundef nonnull %0, ptr noundef %1) #2
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %27, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %34, %27, %.preheader, %12, %6
  %.1 = phi i64 [ %10, %6 ], [ %17, %12 ], [ %17, %.preheader ], [ %38, %27 ], [ %38, %34 ]
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %40, null
  br i1 %.not, label %46, label %41

41:                                               ; preds = %.loopexit
  %42 = load ptr, ptr @gBS, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 112
  %44 = load ptr, ptr %43, align 8, !tbaa !21
  %45 = call i64 %44(ptr noundef nonnull %40) #2
  br label %46

46:                                               ; preds = %.loopexit, %41, %2
  %.012 = phi i64 [ -9223372036854775806, %2 ], [ %.1, %41 ], [ %.1, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  ret i64 %.012
}

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

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

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !6, i64 80}
!10 = !{!"", !11, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !6, i64 88}
!15 = !{!10, !6, i64 120}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !6, i64 64}
!19 = !{!"_EFI_TCP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!20 = !{!19, !6, i64 8}
!21 = !{!10, !6, i64 112}


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