; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/Ip6Dxe (Ip6TxTokenValid)

; 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_IP6_COMPLETION_TOKEN = type { ptr, i64, %union.anon.0 }
%union.anon.0 = type { ptr }
%struct._EFI_IP6_TRANSMIT_DATA = type { %struct.EFI_IPv6_ADDRESS, ptr, i32, ptr, i8, i32, i32, [1 x %struct._EFI_IP6_FRAGMENT_DATA] }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct._EFI_IP6_FRAGMENT_DATA = type { i32, 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: nounwind uwtable
define dso_local i64 @Ip6TxTokenValid(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %15, label %10

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.EFI_IP6_COMPLETION_TOKEN, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %10, %1
  store i64 -9223372036854775806, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %97

16:                                               ; preds = %10
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EFI_IP6_COMPLETION_TOKEN, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  store ptr %19, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %32, label %22

22:                                               ; preds = %16
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %33

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %27, %16
  store i64 -9223372036854775806, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %97

33:                                               ; preds = %27, %22
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %34, i32 0, i32 6
  %36 = load i32, ptr %35, align 8, !tbaa !18
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %43, label %38

38:                                               ; preds = %33
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %39, i32 0, i32 5
  %41 = load i32, ptr %40, align 4, !tbaa !19
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %38, %33
  store i64 -9223372036854775806, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %97

44:                                               ; preds = %38
  store i32 0, ptr %6, align 4, !tbaa !20
  store i32 0, ptr %5, align 4, !tbaa !20
  br label %45

45:                                               ; preds = %80, %44
  %46 = load i32, ptr %5, align 4, !tbaa !20
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %47, i32 0, i32 6
  %49 = load i32, ptr %48, align 8, !tbaa !18
  %50 = icmp ult i32 %46, %49
  br i1 %50, label %51, label %83

51:                                               ; preds = %45
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %52, i32 0, i32 7
  %54 = load i32, ptr %5, align 4, !tbaa !20
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds [1 x %struct._EFI_IP6_FRAGMENT_DATA], ptr %53, i64 0, i64 %55
  %57 = getelementptr inbounds %struct._EFI_IP6_FRAGMENT_DATA, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !21
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %69, label %60

60:                                               ; preds = %51
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %61, i32 0, i32 7
  %63 = load i32, ptr %5, align 4, !tbaa !20
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds [1 x %struct._EFI_IP6_FRAGMENT_DATA], ptr %62, i64 0, i64 %64
  %66 = getelementptr inbounds %struct._EFI_IP6_FRAGMENT_DATA, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !23
  %68 = icmp eq ptr %67, null
  br i1 %68, label %69, label %70

69:                                               ; preds = %60, %51
  store i64 -9223372036854775806, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %97

70:                                               ; preds = %60
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %71, i32 0, i32 7
  %73 = load i32, ptr %5, align 4, !tbaa !20
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds [1 x %struct._EFI_IP6_FRAGMENT_DATA], ptr %72, i64 0, i64 %74
  %76 = getelementptr inbounds %struct._EFI_IP6_FRAGMENT_DATA, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !21
  %78 = load i32, ptr %6, align 4, !tbaa !20
  %79 = add i32 %78, %77
  store i32 %79, ptr %6, align 4, !tbaa !20
  br label %80

80:                                               ; preds = %70
  %81 = load i32, ptr %5, align 4, !tbaa !20
  %82 = add i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !20
  br label %45, !llvm.loop !24

83:                                               ; preds = %45
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %84, i32 0, i32 5
  %86 = load i32, ptr %85, align 4, !tbaa !19
  %87 = load i32, ptr %6, align 4, !tbaa !20
  %88 = icmp ne i32 %86, %87
  br i1 %88, label %89, label %90

89:                                               ; preds = %83
  store i64 -9223372036854775806, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %97

90:                                               ; preds = %83
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._EFI_IP6_TRANSMIT_DATA, ptr %91, i32 0, i32 5
  %93 = load i32, ptr %92, align 4, !tbaa !19
  %94 = icmp ugt i32 %93, 65536
  br i1 %94, label %95, label %96

95:                                               ; preds = %90
  store i64 -9223372036854775804, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %97

96:                                               ; preds = %90
  store i64 0, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %97

97:                                               ; preds = %96, %95, %89, %69, %43, %32, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %98 = load i64, ptr %2, align 8
  ret i64 %98
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !7, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !16, i64 24}
!14 = !{!"_EFI_IP6_TRANSMIT_DATA", !15, i64 0, !6, i64 16, !16, i64 24, !6, i64 32, !7, i64 40, !16, i64 44, !16, i64 48, !7, i64 56}
!15 = !{!"", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!14, !6, i64 32}
!18 = !{!14, !16, i64 48}
!19 = !{!14, !16, i64 44}
!20 = !{!16, !16, i64 0}
!21 = !{!22, !16, i64 0}
!22 = !{!"_EFI_IP6_FRAGMENT_DATA", !16, i64 0, !6, i64 8}
!23 = !{!22, !6, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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

%struct._EFI_IP6_FRAGMENT_DATA = type { i32, ptr }

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @Ip6TxTokenValid(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = icmp eq ptr %8, null
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %8, i64 24
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %17, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %8, i64 32
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = icmp eq ptr %15, null
  br i1 %16, label %.loopexit, label %17

17:                                               ; preds = %13, %10
  %18 = getelementptr inbounds i8, ptr %8, i64 48
  %19 = load i32, ptr %18, align 8, !tbaa !17
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %8, i64 44
  %23 = load i32, ptr %22, align 4, !tbaa !18
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %21
  %25 = getelementptr inbounds i8, ptr %8, i64 56
  %wide.trip.count = zext i32 %19 to i64
  br label %26

26:                                               ; preds = %.preheader, %34
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %34 ]
  %.030 = phi i32 [ 0, %.preheader ], [ %35, %34 ]
  %27 = getelementptr inbounds [1 x %struct._EFI_IP6_FRAGMENT_DATA], ptr %25, i64 0, i64 %indvars.iv
  %28 = load i32, ptr %27, align 8, !tbaa !19
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %.loopexit, label %30

30:                                               ; preds = %26
  %31 = getelementptr inbounds i8, ptr %27, i64 8
  %32 = load ptr, ptr %31, align 8, !tbaa !21
  %33 = icmp eq ptr %32, null
  br i1 %33, label %.loopexit, label %34

34:                                               ; preds = %30
  %35 = add i32 %28, %.030
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %36, label %26, !llvm.loop !22

36:                                               ; preds = %34
  %.not27 = icmp eq i32 %23, %35
  br i1 %.not27, label %37, label %.loopexit

37:                                               ; preds = %36
  %38 = icmp ugt i32 %23, 65536
  %. = select i1 %38, i64 -9223372036854775804, i64 0
  br label %.loopexit

.loopexit:                                        ; preds = %26, %30, %37, %36, %17, %21, %6, %13, %1, %3
  %.022 = phi i64 [ -9223372036854775806, %3 ], [ -9223372036854775806, %1 ], [ -9223372036854775806, %13 ], [ -9223372036854775806, %6 ], [ -9223372036854775806, %21 ], [ -9223372036854775806, %17 ], [ -9223372036854775806, %36 ], [ %., %37 ], [ -9223372036854775806, %30 ], [ -9223372036854775806, %26 ]
  ret i64 %.022
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !8, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !15, i64 24}
!13 = !{!"_EFI_IP6_TRANSMIT_DATA", !14, i64 0, !7, i64 16, !15, i64 24, !7, i64 32, !8, i64 40, !15, i64 44, !15, i64 48, !8, i64 56}
!14 = !{!"", !8, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = !{!13, !7, i64 32}
!17 = !{!13, !15, i64 48}
!18 = !{!13, !15, i64 44}
!19 = !{!20, !15, i64 0}
!20 = !{!"_EFI_IP6_FRAGMENT_DATA", !15, i64 0, !7, i64 8}
!21 = !{!20, !7, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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