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

; 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._MTFTP6_SERVICE = type { i32, %struct._EFI_SERVICE_BINDING_PROTOCOL, ptr, ptr, i16, %struct._LIST_ENTRY, ptr, ptr }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._MTFTP6_INSTANCE = type { i32, ptr, %struct._LIST_ENTRY, %struct._EFI_MTFTP6_PROTOCOL, ptr, ptr, ptr, %struct.MTFTP6_EXT_OPTION_INFO, i16, i16, %struct._LIST_ENTRY, %struct.EFI_IPv6_ADDRESS, i16, i16, ptr, %struct.EFI_IPv6_ADDRESS, i16, ptr, ptr, i32, i32, i32, i32, i64, i8, i8, i8 }
%struct._EFI_MTFTP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.MTFTP6_EXT_OPTION_INFO = type { i16, i8, i32, %struct.EFI_IPv6_ADDRESS, i16, i8, i32 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct._EFI_MTFTP6_TOKEN = type { i64, ptr, ptr, ptr, ptr, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr }

@.str.5 = external hidden unnamed_addr constant [38 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

; 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
declare dso_local i64 @Mtftp6TransmitPacket(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Mtftp6SendError(ptr noundef, i16 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @Mtftp6OperationClean(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @Mtftp6OnTimerTick(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._MTFTP6_SERVICE, ptr %12, i32 0, i32 5
  %14 = getelementptr inbounds %struct._LIST_ENTRY, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._LIST_ENTRY, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  store ptr %18, ptr %8, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %88, %2
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._MTFTP6_SERVICE, ptr %21, i32 0, i32 5
  %23 = icmp ne ptr %20, %22
  br i1 %23, label %24, label %93

24:                                               ; preds = %19
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = ptrtoint ptr %25 to i64
  %27 = sub i64 %26, ptrtoint (ptr getelementptr inbounds (%struct._MTFTP6_INSTANCE, ptr null, i32 0, i32 2) to i64)
  %28 = inttoptr i64 %27 to ptr
  store ptr %28, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %29, i32 0, i32 6
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %24
  br label %88

34:                                               ; preds = %24
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %35, i32 0, i32 21
  %37 = load i32, ptr %36, align 8, !tbaa !22
  %38 = icmp ugt i32 %37, 0
  br i1 %38, label %39, label %44

39:                                               ; preds = %34
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %40, i32 0, i32 21
  %42 = load i32, ptr %41, align 8, !tbaa !22
  %43 = add i32 %42, -1
  store i32 %43, ptr %41, align 8, !tbaa !22
  br label %88

44:                                               ; preds = %34
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %45, i32 0, i32 19
  %47 = load i32, ptr %46, align 8, !tbaa !23
  %48 = add i32 %47, 1
  store i32 %48, ptr %46, align 8, !tbaa !23
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %49, i32 0, i32 6
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  store ptr %51, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._EFI_MTFTP6_TOKEN, ptr %52, i32 0, i32 11
  %54 = load ptr, ptr %53, align 8, !tbaa !24
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %71

56:                                               ; preds = %44
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._EFI_MTFTP6_TOKEN, ptr %57, i32 0, i32 11
  %59 = load ptr, ptr %58, align 8, !tbaa !24
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = call i64 %59(ptr noundef %61, ptr noundef %62)
  store i64 %63, ptr %10, align 8, !tbaa !26
  %64 = load i64, ptr %10, align 8, !tbaa !26
  %65 = icmp slt i64 %64, 0
  br i1 %65, label %66, label %70

66:                                               ; preds = %56
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = call i64 @Mtftp6SendError(ptr noundef %67, i16 noundef zeroext 8, ptr noundef @.str.5)
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  call void @Mtftp6OperationClean(ptr noundef %69, i64 noundef -9223372036854775787)
  br label %88

70:                                               ; preds = %56
  br label %71

71:                                               ; preds = %70, %44
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %72, i32 0, i32 19
  %74 = load i32, ptr %73, align 8, !tbaa !23
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %75, i32 0, i32 20
  %77 = load i32, ptr %76, align 4, !tbaa !27
  %78 = icmp ult i32 %74, %77
  br i1 %78, label %79, label %85

79:                                               ; preds = %71
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %81, i32 0, i32 18
  %83 = load ptr, ptr %82, align 8, !tbaa !28
  %84 = call i64 @Mtftp6TransmitPacket(ptr noundef %80, ptr noundef %83)
  br label %87

85:                                               ; preds = %71
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  call void @Mtftp6OperationClean(ptr noundef %86, i64 noundef -9223372036854775790)
  br label %88

87:                                               ; preds = %79
  br label %88

88:                                               ; preds = %87, %85, %66, %39, %33
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %89, ptr %7, align 8, !tbaa !5
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct._LIST_ENTRY, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !15
  store ptr %92, ptr %8, align 8, !tbaa !5
  br label %19, !llvm.loop !29

93:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

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 48}
!10 = !{!"_MTFTP6_SERVICE", !11, i64 0, !12, i64 8, !6, i64 24, !6, i64 32, !13, i64 40, !14, i64 48, !6, i64 64, !6, i64 72}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 0}
!16 = !{!17, !6, i64 112}
!17 = !{!"_MTFTP6_INSTANCE", !11, i64 0, !6, i64 8, !14, i64 16, !18, i64 32, !6, i64 96, !6, i64 104, !6, i64 112, !19, i64 120, !13, i64 152, !13, i64 154, !14, i64 160, !20, i64 176, !13, i64 192, !13, i64 194, !6, i64 200, !20, i64 208, !13, i64 224, !6, i64 232, !6, i64 240, !11, i64 248, !11, i64 252, !11, i64 256, !11, i64 260, !21, i64 264, !7, i64 272, !7, i64 273, !7, i64 274}
!18 = !{!"_EFI_MTFTP6_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}
!19 = !{!"", !13, i64 0, !7, i64 2, !11, i64 4, !20, i64 8, !13, i64 24, !7, i64 26, !11, i64 28}
!20 = !{!"", !7, i64 0}
!21 = !{!"long long", !7, i64 0}
!22 = !{!17, !11, i64 256}
!23 = !{!17, !11, i64 248}
!24 = !{!25, !6, i64 88}
!25 = !{!"_EFI_MTFTP6_TOKEN", !21, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !21, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!26 = !{!21, !21, i64 0}
!27 = !{!17, !11, i64 252}
!28 = !{!17, !6, i64 240}
!29 = distinct !{!29, !30}
!30 = !{!"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"

@.str.5 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Mtftp6TransmitPacket(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @Mtftp6SendError(ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @Mtftp6OperationClean(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Mtftp6OnTimerTick(ptr nocapture noundef readnone %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 48
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not30 = icmp eq ptr %4, %3
  br i1 %.not30, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %38
  %.031 = phi ptr [ %.02432, %38 ], [ %4, %2 ]
  %.02432 = load ptr, ptr %.031, align 8, !tbaa !14
  %5 = ptrtoint ptr %.031 to i64
  %6 = add i64 %5, -16
  %7 = inttoptr i64 %6 to ptr
  %8 = getelementptr inbounds i8, ptr %7, i64 112
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = icmp eq ptr %9, null
  br i1 %10, label %38, label %11

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds i8, ptr %7, i64 256
  %13 = load i32, ptr %12, align 8, !tbaa !21
  %.not27 = icmp eq i32 %13, 0
  br i1 %.not27, label %16, label %14

14:                                               ; preds = %11
  %15 = add i32 %13, -1
  store i32 %15, ptr %12, align 8, !tbaa !21
  br label %38

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %7, i64 248
  %18 = load i32, ptr %17, align 8, !tbaa !22
  %19 = add i32 %18, 1
  store i32 %19, ptr %17, align 8, !tbaa !22
  %20 = getelementptr inbounds i8, ptr %9, i64 88
  %21 = load ptr, ptr %20, align 8, !tbaa !23
  %.not28 = icmp eq ptr %21, null
  br i1 %.not28, label %28, label %22

22:                                               ; preds = %16
  %23 = getelementptr inbounds i8, ptr %7, i64 32
  %24 = tail call i64 %21(ptr noundef nonnull %23, ptr noundef nonnull %9) #1
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %26, label %._crit_edge33

._crit_edge33:                                    ; preds = %22
  %.pre = load i32, ptr %17, align 8, !tbaa !22
  br label %28

26:                                               ; preds = %22
  %27 = tail call i64 @Mtftp6SendError(ptr noundef nonnull %7, i16 noundef zeroext 8, ptr noundef nonnull @.str.5)
  tail call void @Mtftp6OperationClean(ptr noundef nonnull %7, i64 noundef -9223372036854775787)
  br label %38

28:                                               ; preds = %._crit_edge33, %16
  %29 = phi i32 [ %.pre, %._crit_edge33 ], [ %19, %16 ]
  %30 = getelementptr inbounds i8, ptr %7, i64 252
  %31 = load i32, ptr %30, align 4, !tbaa !25
  %32 = icmp ult i32 %29, %31
  br i1 %32, label %33, label %37

33:                                               ; preds = %28
  %34 = getelementptr inbounds i8, ptr %7, i64 240
  %35 = load ptr, ptr %34, align 8, !tbaa !26
  %36 = tail call i64 @Mtftp6TransmitPacket(ptr noundef nonnull %7, ptr noundef %35)
  br label %38

37:                                               ; preds = %28
  tail call void @Mtftp6OperationClean(ptr noundef nonnull %7, i64 noundef -9223372036854775790)
  br label %38

38:                                               ; preds = %.lr.ph, %33, %37, %26, %14
  %.not = icmp eq ptr %.02432, %3
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !27

._crit_edge:                                      ; preds = %38, %2
  ret void
}

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 = { 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, !11, i64 48}
!6 = !{!"_MTFTP6_SERVICE", !7, i64 0, !10, i64 8, !11, i64 24, !11, i64 32, !12, i64 40, !13, i64 48, !11, i64 64, !11, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!14 = !{!13, !11, i64 0}
!15 = !{!16, !11, i64 112}
!16 = !{!"_MTFTP6_INSTANCE", !7, i64 0, !11, i64 8, !13, i64 16, !17, i64 32, !11, i64 96, !11, i64 104, !11, i64 112, !18, i64 120, !12, i64 152, !12, i64 154, !13, i64 160, !19, i64 176, !12, i64 192, !12, i64 194, !11, i64 200, !19, i64 208, !12, i64 224, !11, i64 232, !11, i64 240, !7, i64 248, !7, i64 252, !7, i64 256, !7, i64 260, !20, i64 264, !8, i64 272, !8, i64 273, !8, i64 274}
!17 = !{!"_EFI_MTFTP6_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!18 = !{!"", !12, i64 0, !8, i64 2, !7, i64 4, !19, i64 8, !12, i64 24, !8, i64 26, !7, i64 28}
!19 = !{!"", !8, i64 0}
!20 = !{!"long long", !8, i64 0}
!21 = !{!16, !7, i64 256}
!22 = !{!16, !7, i64 248}
!23 = !{!24, !11, i64 88}
!24 = !{!"_EFI_MTFTP6_TOKEN", !20, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !11, i64 48, !20, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96}
!25 = !{!16, !7, i64 252}
!26 = !{!16, !11, i64 240}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass